Browse Source

abci/server: recover from app panics in socket server (#3809)

fixes #3800
pull/3816/head
Roman Useinov 5 years ago
committed by Anton Kaliaev
parent
commit
a76c503dc6
2 changed files with 12 additions and 1 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +11
    -1
      abci/server/socket_server.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -18,5 +18,6 @@ program](https://hackerone.com/tendermint).
### FEATURES:
### IMPROVEMENTS:
- [abci] \#3809 Recover from application panics in `server/socket_server.go` to allow socket cleanup (@ruseinov)
### BUG FIXES:

+ 11
- 1
abci/server/socket_server.go View File

@ -146,6 +146,16 @@ func (s *SocketServer) waitForClose(closeConn chan error, connID int) {
func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, responses chan<- *types.Response) {
var count int
var bufReader = bufio.NewReader(conn)
defer func() {
// make sure to recover from any app-related panics to allow proper socket cleanup
r := recover()
if r != nil {
closeConn <- fmt.Errorf("recovered from panic: %v", r)
s.appMtx.Unlock()
}
}()
for {
var req = &types.Request{}
@ -154,7 +164,7 @@ func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, respo
if err == io.EOF {
closeConn <- err
} else {
closeConn <- fmt.Errorf("Error reading message: %v", err.Error())
closeConn <- fmt.Errorf("error reading message: %v", err)
}
return
}


Loading…
Cancel
Save