Skip to content

Commit

Permalink
Don't send on a closed channel
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Oct 15, 2023
1 parent ac85264 commit 909a23c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 10 additions & 3 deletions network/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ func (engine *Engine) Stop(ctx context.Context) error {
} else {
engine.logger.Error().Msg("Listener is not initialized")
}
engine.stopServer <- struct{}{}
close(engine.stopServer)
return err //nolint:wrapcheck

select {
case <-engine.stopServer:
engine.logger.Info().Msg("Server stopped")
return err //nolint:wrapcheck
default:
engine.stopServer <- struct{}{}
close(engine.stopServer)
return err //nolint:wrapcheck
}
}

// NewEngine creates a new engine.
Expand Down
2 changes: 0 additions & 2 deletions network/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestEngine(t *testing.T) {
assert.Zero(t, engine.connections)
})

t.Log(output)

// Expected output:
assert.Contains(t, output, "ERR Listener is not initialized")
}

0 comments on commit 909a23c

Please sign in to comment.