Skip to content

Commit

Permalink
Clear queues on exit to ensure all user context references are gone, …
Browse files Browse the repository at this point in the history
…ref #628
  • Loading branch information
kaetemi committed Mar 4, 2023
1 parent 341fb82 commit ca416fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
14 changes: 11 additions & 3 deletions ryzom/server/src/frontend_service/fe_receive_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,17 @@ void CFeReceiveSub::release()

nlassert( _ReceiveTask != NULL );
nlassert( _ReceiveThread != NULL );

delete m_QuicTransceiver;
m_QuicTransceiver = nullptr;

if (m_QuicTransceiver)
{
m_QuicTransceiver->stop();

m_QuicTransceiver->clearQueue(&m_Queues[2]);
m_QuicTransceiver->clearQueue(&m_Queues[3]);

delete m_QuicTransceiver;
m_QuicTransceiver = nullptr;
}

_ReceiveTask->requireExit();
#ifdef NL_OS_UNIX
Expand Down
33 changes: 32 additions & 1 deletion ryzom/server/src/frontend_service/quic_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ void CQuicTransceiver::stop()
m->Listener = null;
nldebug("Listener closed");
}

// Clear queue
nldebug("Clear current write queue");
clearQueue(m->Buffer);
nldebug("Cleared");
}

void CQuicTransceiver::release()
Expand Down Expand Up @@ -645,12 +650,33 @@ void CQuicTransceiver::shutdownReceived(CQuicUserContext *user)

NLMISC::CBufFIFO *CQuicTransceiver::swapWriteQueue(NLMISC::CBufFIFO *writeQueue)
{
CAtomicFlagLockYield lock(m->BufferMutex);
CAtomicFlagLock lock(m->BufferMutex);
CBufFIFO *previous = m->Buffer;
m->Buffer = writeQueue;
return previous;
}

void CQuicTransceiver::clearQueue(NLMISC::CBufFIFO *queue)
{
CAtomicFlagLockYield lock(m->BufferMutex);
while (!queue->empty())
{
// Data, don't care
queue->pop();
nlassert(!queue->empty());
uint8 *buffer;
uint32 size;
// User ptr, need to decrease ref
queue->front(buffer, size);
CQuicUserContext *user;
nlassert(size == sizeof(user));
memcpy(&user, buffer, size);
// Decrease ref count after pop
CQuicUserContextRelease releaseUser(user);
queue->pop();
}
}

// void CQuicTransceiver::sendDatagram(CQuicUserContext *user, const uint8 *buffer, uint32 size)
//{
// QUIC_BUFFER *buf = new QUIC_BUFFER(); // wow leak :)
Expand Down Expand Up @@ -768,6 +794,11 @@ NLMISC::CBufFIFO *CQuicTransceiver::swapWriteQueue(NLMISC::CBufFIFO *writeQueue)
return previous;
}

void CQuicTransceiver::clearQueue(NLMISC::CBufFIFO *writeQueue)
{

}

bool CQuicTransceiver::sendDatagramSwap(CQuicUserContext *user, NLMISC::CBitMemStream &buffer)
{
return false;
Expand Down
3 changes: 3 additions & 0 deletions ryzom/server/src/frontend_service/quic_transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ class CQuicTransceiver
/// Set new write queue for incoming messages (thread-safe because mutexed)
NLMISC::CBufFIFO *swapWriteQueue(NLMISC::CBufFIFO *writeQueue);

/// Clear a write queue safely
void clearQueue(NLMISC::CBufFIFO *writeQueue);

/// Check if still listening
bool listening();

Expand Down

0 comments on commit ca416fd

Please sign in to comment.