Browse Source

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

fixes #3800
pull/3926/head
Roman Useinov 6 years ago
committed by Jack Zampolin
parent
commit
9867a65de7
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: ### FEATURES:
### IMPROVEMENTS: ### IMPROVEMENTS:
- [abci] \#3809 Recover from application panics in `server/socket_server.go` to allow socket cleanup (@ruseinov)
### BUG FIXES: ### 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) { func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, responses chan<- *types.Response) {
var count int var count int
var bufReader = bufio.NewReader(conn) 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 { for {
var req = &types.Request{} var req = &types.Request{}
@ -154,7 +164,7 @@ func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, respo
if err == io.EOF { if err == io.EOF {
closeConn <- err closeConn <- err
} else { } else {
closeConn <- fmt.Errorf("Error reading message: %v", err.Error())
closeConn <- fmt.Errorf("error reading message: %v", err)
} }
return return
} }


Loading…
Cancel
Save