-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPServer Applications Slow to Terminate #3796 #3797
Conversation
- Queue a StopNotification for each thread in the TCPServerDispatcher thread pool. Otherwise, only one thread in the thread pool is terminated. Signed-off-by: Stephen Balousek <sbalousek@wickedloop.com>
Is there a reason this couldn't use |
@Burgch I think you are right, this change does not guarantee that all threads will receive the notification; also, with |
I was going to create a pull request based on diff, but I don't think it fully solves the problem. The issue is that there could always be threads that are in the loop after the end of the lock scope but not yet started waiting in the call to I think the existing code (this PR) is actually correct, because it ensures there are at least as many notifications as there could be threads which are currently waiting, or about to start waiting. I think using |
|
Agreed - I think the only change I'd now suggest is to switch to queuing only |
@Burgch diff --git a/Net/src/TCPServerDispatcher.cpp b/Net/src/TCPServerDispatcher.cpp
index 2d974ae93..05d1840fb 100644
--- a/Net/src/TCPServerDispatcher.cpp
+++ b/Net/src/TCPServerDispatcher.cpp
@@ -140,11 +140,18 @@ namespace
void TCPServerDispatcher::enqueue(const StreamSocket& socket)
{
+ if (_stopped)
+ {
+ ++_refusedConnections;
+ return;
+ }
+
FastMutex::ScopedLock lock(_mutex);
if (_queue.size() < _pParams->getMaxQueued())
{
_queue.enqueueNotification(new TCPConnectionNotification(socket));
+
if (!_queue.hasIdleThreads() && _currentThreads < _pParams->getMaxThreads())
{
try
@@ -172,8 +179,9 @@ void TCPServerDispatcher::enqueue(const StreamSocket& socket)
void TCPServerDispatcher::stop()
{
+ if (_stopped.exchange(true)) return;
+
FastMutex::ScopedLock lock(_mutex);
- _stopped = true;
_queue.clear();
for (int i = 0; i < _threadPool.allocated(); i++)
{ |
@aleks-f I don't believe that is necessary, thanks to
|
Signed-off-by: Stephen Balousek sbalousek@wickedloop.com