SolidWallOfCode commented on a change in pull request #8500:
URL: https://github.com/apache/trafficserver/pull/8500#discussion_r749785699



##########
File path: src/traffic_server/traffic_server.cc
##########
@@ -185,10 +185,21 @@ PID of the traffic_server process (second column of 
output).
 */
 static int cmd_block = 0;
 
-// 1: the main thread delayed accepting, start accepting.
-// 0: delay accept, wait for cache initialization.
-// -1: cache is already initialized, don't delay.
-static int delay_listen_for_cache = 0;
+namespace
+{
+/** State of waiting for cache to initialize.
+ * Transitions:
+ * WAIT -> DELAYED : wait enabled and proxy initialization was delayed.
+ * WAIT -> INITIALIZED : cache is initialized before delay, don't delay.
+ * DELAYED -> INITIALIZED : cache is initialized, need to proxy init after 
delay.
+ */
+enum class CacheWaitState {
+  WAIT        = 0, ///< Wait for initialization
+  DELAYED     = 1, ///< The waiting has started.
+  INITIALIZED = -1 ///< Cache is initialized, no more waiting.
+};
+std::atomic<CacheWaitState> delay_listen_for_cache{CacheWaitState::WAIT};

Review comment:
       The cache initialization is proceeding asynchronously and can complete 
at the same time as the main thread is about to check. Setting to `DELAYED` or 
`INITIALIZED` can therefore be a race.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to