Merge pull request #366 from jolavillette/fix/jsonapi-stop-api-before-plugins

Stop the JSON API before plugins delete their resource providers
This commit is contained in:
csoler 2026-08-28 11:29:15 +02:00 committed by GitHub
commit 72d9d16833
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,6 +84,21 @@ void RsServer::rsGlobalShutDown()
bool wasReady = coreReady; bool wasReady = coreReady;
coreReady = false; coreReady = false;
#ifdef RS_JSONAPI
/* Stop the JSON API before anything else. Plugins delete their
* JsonApiResourceProvider in stopPlugins() below, while the restbed service
* still holds the resources that provider handed out -- their handlers
* capture it, so serving a request in that window dereferences freed
* memory. The window is not small: everything between stopPlugins() and the
* end of this function can take tens of seconds, and a web interface polls
* throughout. Stopping first also keeps an API client from touching the
* configuration after ConfigFinalSave().
*
* Not inside the wasReady branch: retroshare-service and Android start the
* JSON API before login, so a shutdown from that state must stop it too. */
if(rsJsonApi) rsJsonApi->fullstop();
#endif
if(wasReady) if(wasReady)
{ {
/* Close the incoming-connection listener FIRST, before anything else. /* Close the incoming-connection listener FIRST, before anything else.
@ -123,10 +138,6 @@ void RsServer::rsGlobalShutDown()
* iterating the peer list concurrently. */ * iterating the peer list concurrently. */
if(pqih) pqih->fullstopAllThreads(); if(pqih) pqih->fullstopAllThreads();
#ifdef RS_JSONAPI
if(rsJsonApi) rsJsonApi->fullstop();
#endif
AuthPGP::exit(); AuthPGP::exit();
// close all databases // close all databases