mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
http: Avoid crash when g_thread_http was never started
g_thread_http can not be joined when it is not joinable. Avoid crashing the node by adding the required check and add a test.
This commit is contained in:
@@ -421,7 +421,7 @@ bool UpdateHTTPServerLogging(bool enable) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::thread threadHTTP;
|
static std::thread g_thread_http;
|
||||||
static std::vector<std::thread> g_thread_http_workers;
|
static std::vector<std::thread> g_thread_http_workers;
|
||||||
|
|
||||||
void StartHTTPServer()
|
void StartHTTPServer()
|
||||||
@@ -429,7 +429,7 @@ void StartHTTPServer()
|
|||||||
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
|
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
|
||||||
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
|
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
|
||||||
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
|
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
|
||||||
threadHTTP = std::thread(ThreadHTTP, eventBase);
|
g_thread_http = std::thread(ThreadHTTP, eventBase);
|
||||||
|
|
||||||
for (int i = 0; i < rpcThreads; i++) {
|
for (int i = 0; i < rpcThreads; i++) {
|
||||||
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue, i);
|
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue, i);
|
||||||
@@ -467,7 +467,7 @@ void StopHTTPServer()
|
|||||||
boundSockets.clear();
|
boundSockets.clear();
|
||||||
if (eventBase) {
|
if (eventBase) {
|
||||||
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
|
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
|
||||||
threadHTTP.join();
|
if (g_thread_http.joinable()) g_thread_http.join();
|
||||||
}
|
}
|
||||||
if (eventHTTP) {
|
if (eventHTTP) {
|
||||||
evhttp_free(eventHTTP);
|
evhttp_free(eventHTTP);
|
||||||
|
|||||||
@@ -99,5 +99,13 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
self.test_auth(self.nodes[1], self.rpcuser, self.rpcpassword)
|
self.test_auth(self.nodes[1], self.rpcuser, self.rpcpassword)
|
||||||
|
|
||||||
|
self.log.info('Check that failure to write cookie file will abort the node gracefully')
|
||||||
|
self.stop_node(0)
|
||||||
|
cookie_file = os.path.join(get_datadir_path(self.options.tmpdir, 0), self.chain, '.cookie.tmp')
|
||||||
|
os.mkdir(cookie_file)
|
||||||
|
init_error = 'Error: Unable to start HTTP server. See debug log for details.'
|
||||||
|
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
HTTPBasicsTest().main()
|
HTTPBasicsTest().main()
|
||||||
|
|||||||
Reference in New Issue
Block a user