File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -285,9 +285,10 @@ func (c *Connection) setupConnection() error {
285
285
if ! ok {
286
286
return
287
287
}
288
- if errors .Is (err , io .EOF ) || errors .Is (err , io .ErrUnexpectedEOF ) {
289
- // Return a bare io.EOF error if error is EOF/ErrUnexpectedEOF
290
- c .errorChan <- io .EOF
288
+ var connErr * muxer.ConnectionClosedError
289
+ if errors .As (err , & connErr ) {
290
+ // Pass through ConnectionClosedError from muxer
291
+ c .errorChan <- err
291
292
} else {
292
293
// Wrap error message to denote it comes from the muxer
293
294
c .errorChan <- fmt .Errorf ("muxer error: %w" , err )
@@ -354,7 +355,7 @@ func (c *Connection) setupConnection() error {
354
355
select {
355
356
case <- c .doneChan :
356
357
// Return an error if we're shutting down
357
- return io .EOF
358
+ return fmt . Errorf ( "connection shutdown initiated: %w" , io .EOF )
358
359
case err := <- c .protoErrorChan :
359
360
// Shutdown the connection and return the error
360
361
c .Close ()
Original file line number Diff line number Diff line change @@ -69,6 +69,19 @@ type Muxer struct {
69
69
onceStop sync.Once
70
70
}
71
71
72
+ type ConnectionClosedError struct {
73
+ Context string
74
+ Err error
75
+ }
76
+
77
+ func (e * ConnectionClosedError ) Error () string {
78
+ return fmt .Sprintf ("peer closed the connection while %s: %v" , e .Context , e .Err )
79
+ }
80
+
81
+ func (e * ConnectionClosedError ) Unwrap () error {
82
+ return e .Err
83
+ }
84
+
72
85
// New creates a new Muxer object and starts the read loop
73
86
func New (conn net.Conn ) * Muxer {
74
87
m := & Muxer {
@@ -287,7 +300,11 @@ func (m *Muxer) readLoop() {
287
300
if errors .Is (err , io .ErrClosedPipe ) {
288
301
err = io .EOF
289
302
}
290
- m .sendError (err )
303
+ if errors .Is (err , io .EOF ) {
304
+ m .sendError (& ConnectionClosedError {Context : "reading header" , Err : err })
305
+ } else {
306
+ m .sendError (err )
307
+ }
291
308
return
292
309
}
293
310
msg := & Segment {
@@ -300,7 +317,11 @@ func (m *Muxer) readLoop() {
300
317
if errors .Is (err , io .ErrClosedPipe ) {
301
318
err = io .EOF
302
319
}
303
- m .sendError (err )
320
+ if errors .Is (err , io .EOF ) {
321
+ m .sendError (& ConnectionClosedError {Context : "reading payload" , Err : err })
322
+ } else {
323
+ m .sendError (err )
324
+ }
304
325
return
305
326
}
306
327
// Check for message from initiator when we're not configured as a responder
You can’t perform that action at this time.
0 commit comments