From 811324a5705f72ea6b3544acb847048288d944a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Wed, 27 Dec 2023 12:27:18 +0100 Subject: [PATCH] make WalletExtensionContainer non blocking --- .../container/walletextension_container.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/walletextension/container/walletextension_container.go b/tools/walletextension/container/walletextension_container.go index 0214b6cf72..f68b71d713 100644 --- a/tools/walletextension/container/walletextension_container.go +++ b/tools/walletextension/container/walletextension_container.go @@ -149,21 +149,29 @@ func NewWalletExtensionContainer( } } -// TODO Start should not be a locking process +// Start starts the wallet extension container func (w *WalletExtensionContainer) Start() error { httpErrChan := w.httpServer.Start() wsErrChan := w.wsServer.Start() - select { - case err := <-httpErrChan: - if !errors.Is(err, http.ErrServerClosed) { - panic(err) + // Start a goroutine for handling HTTP server errors + go func() { + for err := range httpErrChan { + if !errors.Is(err, http.ErrServerClosed) { + w.logger.Error("HTTP server error: %v", err) + } } - case err := <-wsErrChan: - if !errors.Is(err, http.ErrServerClosed) { - panic(err) + }() + + // Start a goroutine for handling WebSocket server errors + go func() { + for err := range wsErrChan { + if !errors.Is(err, http.ErrServerClosed) { + w.logger.Error("WebSocket server error: %v", err) + } } - } + }() + return nil }