Skip to content

Commit

Permalink
catch panics in handleIncoming and handleOutgoing
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 18, 2022
1 parent d2c4bb4 commit 42401df
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions multiplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"io"
"net"
"os"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -250,6 +252,12 @@ func (mp *Multiplex) sendMsg(timeout, cancel <-chan struct{}, header uint64, dat
}

func (mp *Multiplex) handleOutgoing() {
defer func() {
if rerr := recover(); rerr != nil {
fmt.Fprintf(os.Stderr, "caught panic in handleOutgoing: %s\n%s\n", rerr, debug.Stack())
}
}()

for {
select {
case <-mp.shutdown:
Expand Down Expand Up @@ -349,6 +357,12 @@ func (mp *Multiplex) cleanup() {
}

func (mp *Multiplex) handleIncoming() {
defer func() {
if rerr := recover(); rerr != nil {
fmt.Fprintf(os.Stderr, "caught panic in handleIncoming: %s\n%s\n", rerr, debug.Stack())
}
}()

defer mp.cleanup()

recvTimeout := time.NewTimer(0)
Expand Down

0 comments on commit 42401df

Please sign in to comment.