Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions cmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"net"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -169,6 +170,14 @@ func (m *cMux) Serve() error {
for {
c, err := m.root.Accept()
if err != nil {
if strings.Contains(err.Error(), "use of closed network connection") {
select {
case <-m.donec: // error is expected
return nil
default:
}
}

if !m.handleErr(err) {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
)

func safeServe(errCh chan<- error, muxl CMux) {
if err := muxl.Serve(); !strings.Contains(err.Error(), "use of closed") {
if err := muxl.Serve(); err != nil && !strings.Contains(err.Error(), "use of closed") {
errCh <- err
}
}
Expand Down