From 060d5be06d91f54bb53138fda86fc6c58f9adebe Mon Sep 17 00:00:00 2001 From: Arnaud Bouchez Date: Thu, 31 Aug 2023 12:08:13 +0200 Subject: [PATCH] fixed random blocking of async server - asynchronous and multi-thread programming is hard - race conditions could be difficult to track - I spent a lot of time on this issue, which was reproduced using the wrk tool and a lot of concurrent connections for a long time - it was more easily reproduced on Windows, but could potentially affect all platforms, and may be the culprit of very rare race condition on other platforms like Linux (seen e.g. on TFB) - in fact, it was a one-liner - as often with race conditions :) - just move one flag assignment at the right place --- src/mormot.commit.inc | 2 +- src/net/mormot.net.async.pas | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mormot.commit.inc b/src/mormot.commit.inc index d49a0fd07..f6d1cc9d7 100644 --- a/src/mormot.commit.inc +++ b/src/mormot.commit.inc @@ -1 +1 @@ -'2.1.5811' +'2.1.5812' diff --git a/src/net/mormot.net.async.pas b/src/net/mormot.net.async.pas index 24f55d119..274fcd460 100644 --- a/src/net/mormot.net.async.pas +++ b/src/net/mormot.net.async.pas @@ -1869,8 +1869,8 @@ procedure TAsyncConnectionsThread.Execute; atpReadPending: // secondary threads wait, then read and process pending events begin - fWaitForReadPending := true; fEvent.ResetEvent; + fWaitForReadPending := true; // to be set just before WaitForEver fEvent.WaitForEver; if Terminated then break;