lyind commented on a change in pull request #257: GUACAMOLE-958: Avoid 
race/deadlock in guacd_timed_client_free()
URL: https://github.com/apache/guacamole-server/pull/257#discussion_r378808997
 
 

 ##########
 File path: src/guacd/proc.c
 ##########
 @@ -267,24 +267,24 @@ static int guacd_timed_client_free(guac_client* client, 
int timeout) {
         .tv_nsec = current_time.tv_usec * 1000
     };
 
-    /* Free the client in a separate thread, so we can time the free operation 
*/
-    if (pthread_create(&client_free_thread, NULL,
-                guacd_client_free_thread, &free_operation))
-        return 1;
-
     /* The mutex associated with the pthread conditional and flag MUST be
      * acquired before attempting to wait for the condition */
     if (pthread_mutex_lock(&free_operation.completed_mutex))
         return 1;
 
-    /* Wait a finite amount of time for the free operation to finish */
-    if (pthread_cond_timedwait(&free_operation.completed_cond,
-                &free_operation.completed_mutex, &deadline))
-        return 1;
+    /* Free the client in a separate thread, so we can time the free operation 
*/
+    if (!pthread_create(&client_free_thread, NULL,
+                guacd_client_free_thread, &free_operation)) {
+
+        /* Wait a finite amount of time for the free operation to finish */
+        (void) pthread_cond_timedwait(&free_operation.completed_cond,
 
 Review comment:
   <del>
   Looking at the code again I believe we should put the 
`free_operation->completed = 1;` above the mutex lock in 
`guacd_client_free_thread()` to make sure our load/store barrier works.
   
   In the unlikely case where the free-thread sets completed to 1 after a 
timeout, we don't care about a possible race-condition (returning a late 
success is better than returning a timeout).
   
   </del>
   
   Reading this:
   
https://stackoverflow.com/questions/3208060/does-guarding-a-variable-with-a-pthread-mutex-guarantee-its-also-not-cached
   
   The initial commit was fine. I will revert the second one and force-push.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to