Skip to content

Commit

Permalink
remove old way of calling walletExtContainer.Start() and fix error ha…
Browse files Browse the repository at this point in the history
…ndling
  • Loading branch information
zkokelj committed Dec 27, 2023
1 parent eb1bdf8 commit 871219b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
20 changes: 17 additions & 3 deletions tools/walletextension/container/walletextension_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ func (w *WalletExtensionContainer) Start() error {
for {
select {
case err := <-httpErrChan:
if !errors.Is(err, http.ErrServerClosed) {
if errors.Is(err, http.ErrServerClosed) {
err = w.Stop() // Stop the container when the HTTP server is closed
if err != nil {
fmt.Printf("failed to stop gracefully - %s\n", err)
os.Exit(1)
}
} else {
// for other errors, we just log them
w.logger.Error("HTTP server error: %v", err)
}
case <-w.stopControl.Done():
Expand All @@ -173,8 +180,15 @@ func (w *WalletExtensionContainer) Start() error {
for {
select {
case err := <-wsErrChan:
if !errors.Is(err, http.ErrServerClosed) {
w.logger.Error("WebSocket server error: %v", err)
if errors.Is(err, http.ErrServerClosed) {
err = w.Stop() // Stop the container when the WS server is closed
if err != nil {
fmt.Printf("failed to stop gracefully - %s\n", err)
os.Exit(1)
}
} else {
// for other errors, we just log them
w.logger.Error("HTTP server error: %v", err)
}
case <-w.stopControl.Done():
return // Exit the goroutine when stop signal is received
Expand Down
17 changes: 5 additions & 12 deletions tools/walletextension/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,12 @@ func main() {
logger := log.New(log.WalletExtCmp, int(logLvl), config.LogPath)

walletExtContainer := container.NewWalletExtensionContainerFromConfig(config, logger)
defer func() {
err := walletExtContainer.Start()
if err != nil {
fmt.Printf("error stopping WE - %s", err)
}
}()

go func() {
err := walletExtContainer.Start()
if err != nil {
fmt.Printf("error in WE - %s", err)
}
}()
// Start the wallet extension.
err := walletExtContainer.Start()
if err != nil {
fmt.Printf("error in WE - %s", err)
}

walletExtensionAddr := fmt.Sprintf("%s:%d", common.Localhost, config.WalletExtensionPortHTTP)
fmt.Printf("💡 Wallet extension started \n") // Some tests rely on seeing this message. Removed in next PR.
Expand Down

0 comments on commit 871219b

Please sign in to comment.