mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#9563 Reorganize how and when objects are deleted when shutting down GRPC
This commit is contained in:
@@ -208,13 +208,9 @@ void RiaGrpcServerImpl::quit()
|
|||||||
if ( m_server )
|
if ( m_server )
|
||||||
{
|
{
|
||||||
RiaLogging::info( "Shutting down gRPC server" );
|
RiaLogging::info( "Shutting down gRPC server" );
|
||||||
// Clear unhandled requests
|
|
||||||
while ( !m_unprocessedRequests.empty() )
|
// See the following link for details on how to shut down a GRPC server
|
||||||
{
|
// https://github.com/grpc/grpc/blob/master/include/grpcpp/server_builder.h#L147
|
||||||
RiaGrpcCallbackInterface* method = m_unprocessedRequests.front();
|
|
||||||
m_unprocessedRequests.pop_front();
|
|
||||||
delete method;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shutdown server and queue
|
// Shutdown server and queue
|
||||||
m_server->Shutdown();
|
m_server->Shutdown();
|
||||||
@@ -223,16 +219,41 @@ void RiaGrpcServerImpl::quit()
|
|||||||
// Wait for thread to join after handling the shutdown call
|
// Wait for thread to join after handling the shutdown call
|
||||||
m_thread.join();
|
m_thread.join();
|
||||||
|
|
||||||
|
// Drain the completion queue
|
||||||
|
void* ignored_tag;
|
||||||
|
bool ignored_ok;
|
||||||
|
while ( m_completionQueue->Next( &ignored_tag, &ignored_ok ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Create a set of callbacks to be deleted. The same object may be present in both unprocessed and
|
||||||
|
// allocated. Delete the callbacks before deleting the server and completion queue to avoid crash.
|
||||||
|
|
||||||
|
std::set<RiaGrpcCallbackInterface*> toBeDeleted;
|
||||||
|
for ( auto r : m_unprocessedRequests )
|
||||||
|
{
|
||||||
|
toBeDeleted.insert( r );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( auto r : m_allocatedCallbakcs )
|
||||||
|
{
|
||||||
|
toBeDeleted.insert( r );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_unprocessedRequests.clear();
|
||||||
|
m_allocatedCallbakcs.clear();
|
||||||
|
|
||||||
|
for ( auto r : toBeDeleted )
|
||||||
|
{
|
||||||
|
delete r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Must destroy server before services
|
// Must destroy server before services
|
||||||
m_server.reset();
|
m_server.reset();
|
||||||
m_completionQueue.reset();
|
m_completionQueue.reset();
|
||||||
|
|
||||||
for ( auto c : m_allocatedCallbakcs )
|
|
||||||
{
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
m_allocatedCallbakcs.clear();
|
|
||||||
|
|
||||||
// Finally clear services
|
// Finally clear services
|
||||||
m_services.clear();
|
m_services.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user