Skip to content

Commit a244b79

Browse files
authored
Merge pull request #136 from cloudstruct/feat/conn-close-error-handling
feat: better handling of EOF errors
2 parents 8be1cfb + 8168e87 commit a244b79

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ouroboros.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ouroboros
22

33
import (
4+
"errors"
45
"fmt"
56
"github.com/cloudstruct/go-ouroboros-network/muxer"
67
"github.com/cloudstruct/go-ouroboros-network/protocol"
@@ -11,6 +12,7 @@ import (
1112
"github.com/cloudstruct/go-ouroboros-network/protocol/localstatequery"
1213
"github.com/cloudstruct/go-ouroboros-network/protocol/localtxsubmission"
1314
"github.com/cloudstruct/go-ouroboros-network/protocol/txsubmission"
15+
"io"
1416
"net"
1517
)
1618

@@ -101,7 +103,13 @@ func (o *Ouroboros) setupConnection() error {
101103
if !ok {
102104
return
103105
}
104-
o.ErrorChan <- fmt.Errorf("muxer error: %s", err)
106+
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
107+
// Return a bare io.EOF error if error is EOF/ErrUnexpectedEOF
108+
o.ErrorChan <- io.EOF
109+
} else {
110+
// Wrap error message to denote it comes from the muxer
111+
o.ErrorChan <- fmt.Errorf("muxer error: %s", err)
112+
}
105113
// Close connection on muxer errors
106114
o.Close()
107115
}()

0 commit comments

Comments
 (0)