Make HTTP server shutdown more graceful

Shutting down the HTTP server currently breaks off all current requests.
This can create a race condition with RPC `stop` command, where the calling
process never receives confirmation.

This change removes the listening sockets on shutdown so that no new
requests can come in, but no longer breaks off requests in progress.

Meant to fix bitcoin/#6717.

Zcash: cherry-picked from commit 5e0c22135600fe36811da3b78216efc61ba765fb
This commit is contained in:
Wladimir J. van der Laan
2015-09-24 17:29:22 +02:00
committed by Jason Davies
parent 10acd8a1fb
commit c0fe29370a
2 changed files with 23 additions and 7 deletions

View File

@@ -246,7 +246,8 @@ UniValue stop(const UniValue& params, bool fHelp)
throw runtime_error(
"stop\n"
"\nStop Zcash server.");
// Shutdown will take long enough that the response should get back
// Event loop will exit after current HTTP requests have been handled, so
// this reply will get back to the client.
StartShutdown();
return "Zcash server stopping";
}