From b35af5de9f8141d5f966054a776b8e3d1033269b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 14 Jul 2022 18:22:13 +0200 Subject: [PATCH] Manager: allow requesting shutdown multiple times It's fine to request a shutdown multiple times. This fixes a hard crash due to a panic. --- internal/manager/api_impl/api_impl.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/manager/api_impl/api_impl.go b/internal/manager/api_impl/api_impl.go index 52ef35e2..82daa98f 100644 --- a/internal/manager/api_impl/api_impl.go +++ b/internal/manager/api_impl/api_impl.go @@ -83,6 +83,11 @@ func (f *Flamenco) WaitForShutdown(ctx context.Context) bool { // requestShutdown closes the 'done' channel, signalling to callers of // WaitForShutdown() that a shutdown is requested. func (f *Flamenco) requestShutdown() { + defer func() { + // Recover the panic that happens when the channel is closed multiple times. + // Requesting a shutdown should be possible multiple times without panicing. + recover() + }() close(f.done) }