From 11b07616fa03e56d5447b19fd30929d2fe8a458c Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Tue, 13 Jul 2021 20:38:17 +0100 Subject: [PATCH] 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