From 11b07616fa03e56d5447b19fd30929d2fe8a458c Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Tue, 13 Jul 2021 20:38:17 +0100 Subject: [PATCH 1/2] wait until response is flushed before unsubscribing from broker I am not sure why this works, but it seems to. I have been trying to enable the scaffolder and found that when I view a task in progress or complete that the task just sits with the text "Waiting for logs...". This is a hunch. Signed-off-by: Brian Fletcher --- plugins/scaffolder-backend/src/service/router.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/service/router.ts b/plugins/scaffolder-backend/src/service/router.ts index 2b5bdb3bf8..cee9d2cfb4 100644 --- a/plugins/scaffolder-backend/src/service/router.ts +++ b/plugins/scaffolder-backend/src/service/router.ts @@ -233,17 +233,19 @@ export async function createRouter( ); } + let shouldUnsubscribe = false; for (const event of events) { res.write( `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`, ); if (event.type === 'completion') { - unsubscribe(); + shouldUnsubscribe = true; // Closing the event stream here would cause the frontend // to automatically reconnect because it lost connection. } } res.flush(); + if (shouldUnsubscribe) unsubscribe(); }, ); // When client closes connection we update the clients list From e75506fe71f6fdf38c4caf64f699b0243385bc15 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Wed, 14 Jul 2021 09:12:56 +0100 Subject: [PATCH 2/2] adds changeset file Signed-off-by: Brian Fletcher --- .changeset/big-pens-train.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/big-pens-train.md diff --git a/.changeset/big-pens-train.md b/.changeset/big-pens-train.md new file mode 100644 index 0000000000..5c4f8dc7b0 --- /dev/null +++ b/.changeset/big-pens-train.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Unsubscribe from broker after response is flushed