Skip to content

Commit 89d07a8

Browse files
committed
fix: check for shutdown to avoid hang on close
1 parent 413a3fb commit 89d07a8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

ouroboros.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,19 @@ func (o *Ouroboros) setupConnection() error {
296296
o.waitGroup.Add(1)
297297
go func() {
298298
defer o.waitGroup.Done()
299-
err, ok := <-o.protoErrorChan
300-
// The channel is closed, which means we're already shutting down
301-
if !ok {
299+
select {
300+
case <-o.doneChan:
301+
// Return if we're shutting down
302302
return
303+
case err, ok := <-o.protoErrorChan:
304+
// The channel is closed, which means we're already shutting down
305+
if !ok {
306+
return
307+
}
308+
o.errorChan <- fmt.Errorf("protocol error: %s", err)
309+
// Close connection on mini-protocol errors
310+
o.Close()
303311
}
304-
o.errorChan <- fmt.Errorf("protocol error: %s", err)
305-
// Close connection on mini-protocol errors
306-
o.Close()
307312
}()
308313
// Configure the relevant mini-protocols
309314
if o.useNodeToNodeProto {

0 commit comments

Comments
 (0)