From 9867a65de7f912498636ad58f2d1f29912fe79dd Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 17 Jul 2019 06:37:27 +0200 Subject: [PATCH] abci/server: recover from app panics in socket server (#3809) fixes #3800 --- CHANGELOG_PENDING.md | 1 + abci/server/socket_server.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index fd5c4b27e..41400d892 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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: diff --git a/abci/server/socket_server.go b/abci/server/socket_server.go index 96cb844b7..82ce610ed 100644 --- a/abci/server/socket_server.go +++ b/abci/server/socket_server.go @@ -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 }