Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ func (c *Connection) setupConnection() error {
return
}
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
// Return a bare io.EOF error if error is EOF/ErrUnexpectedEOF
c.errorChan <- io.EOF
// Preserve the original wrapped error with friendly message
c.errorChan <- err
} else {
// Wrap error message to denote it comes from the muxer
c.errorChan <- fmt.Errorf("muxer error: %w", err)
Expand Down Expand Up @@ -354,7 +354,7 @@ func (c *Connection) setupConnection() error {
select {
case <-c.doneChan:
// Return an error if we're shutting down
return io.EOF
return fmt.Errorf("connection shutdown initiated: %w", io.EOF)
case err := <-c.protoErrorChan:
// Shutdown the connection and return the error
c.Close()
Expand Down
14 changes: 8 additions & 6 deletions muxer/muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ func (m *Muxer) readLoop() {
}
header := SegmentHeader{}
if err := binary.Read(m.conn, binary.BigEndian, &header); err != nil {
if errors.Is(err, io.ErrClosedPipe) {
err = io.EOF
if errors.Is(err, io.ErrClosedPipe) || errors.Is(err, io.EOF) {
m.sendError(fmt.Errorf("peer closed the connection while reading header: %w", err))
} else {
m.sendError(err)
}
m.sendError(err)
return
}
msg := &Segment{
Expand All @@ -297,10 +298,11 @@ func (m *Muxer) readLoop() {
// We use ReadFull because it guarantees to read the expected number of bytes or
// return an error
if _, err := io.ReadFull(m.conn, msg.Payload); err != nil {
if errors.Is(err, io.ErrClosedPipe) {
err = io.EOF
if errors.Is(err, io.ErrClosedPipe) || errors.Is(err, io.EOF) {
m.sendError(fmt.Errorf("peer closed the connection while reading payload: %w", err))
} else {
m.sendError(err)
}
m.sendError(err)
return
}
// Check for message from initiator when we're not configured as a responder
Expand Down
Loading