You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2021/06/04 17:29:42 UTC

[GitHub] [qpid-dispatch] mgoulish opened a new pull request #1243: DISPATCH-1956: reduce locking around log src lookup

mgoulish opened a new pull request #1243:
URL: https://github.com/apache/qpid-dispatch/pull/1243


   I noticed that almost all calls to   qd_log_source_lh()  were very simple:  take the lock, call the function, release the lock.
   
   But that means that we could move the lock take-and-release inside of that function, with no change in behavior.
   
   And then that means I don't have to ask the caller to add my new log_source (if it is new) to the list -- I can do that myself from within the function and simplify everything -- but do it after I drop the log_source_lock, so we don't get the lock inversion.
   
   SO I did that, and removed the _lh from the end of the function name -- but that made it collide with the name of another function. So I changed it to qd_log_source_find_or_make().
   I.e. "if you don't find one of this name, then make it."
   
   The only slight disturbance was the function qd_log_entity() which took the lock and used it to cover this function and a couple other calls to a different  _lh() function.    SO for that one I just inserted new take-and-releases of the lock, right around the other function calls.   Now there is only one line of code between each take-and-release, which seems much nicer.
   
   
   Also qd_log_source_reset() bugged me because it called my new function but then immediately had to take the lock just so it could set the log_source to default values. SO I just added a flag to my new fn so that  qd_log_source_reset()  could tell me to do that for him right after I retrieve it.
   
   
   


-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


[GitHub] [qpid-dispatch] ganeshmurthy closed pull request #1243: DISPATCH-1956: reduce locking around log src lookup

Posted by GitBox <gi...@apache.org>.
ganeshmurthy closed pull request #1243:
URL: https://github.com/apache/qpid-dispatch/pull/1243


   


-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1243: DISPATCH-1956: reduce locking around log src lookup

Posted by GitBox <gi...@apache.org>.
kgiusti commented on a change in pull request #1243:
URL: https://github.com/apache/qpid-dispatch/pull/1243#discussion_r646634535



##########
File path: src/log.c
##########
@@ -592,24 +601,22 @@ qd_error_t qd_log_entity(qd_entity_t *entity)
             QD_ERROR_BREAK();
         }
 
-        //
-        // Obtain the log_source_lock lock. This lock is also used when write_log() is called.
-        //
-        sys_mutex_lock(log_source_lock);
-
-        qd_log_source_t *src = qd_log_source_lh(module); /* The original(already existing) log source */
+        qd_log_source_t *src = qd_log_source_find_or_make(module, false); /* The original (already existing) log source */
 
         if (has_output_file) {
+            sys_mutex_lock(log_source_lock);
             log_sink_t* sink = log_sink_lh(outputFile);
+            sys_mutex_unlock(log_source_lock);
             if (!sink) {
                 error_in_output = true;
-                sys_mutex_unlock(log_source_lock);
                 break;
             }
 
             // DEFAULT source may already have a sink, so free the old sink first
             if (src->sink) {
+                sys_mutex_lock(log_source_lock);
                 log_sink_free_lh(src->sink);
+                sys_mutex_unlock(log_source_lock);

Review comment:
       This could be a problem: src->sink has been freed.  Once the lock is dropped some other thread may try to access that stale sink pointer.

##########
File path: src/log.c
##########
@@ -592,24 +601,22 @@ qd_error_t qd_log_entity(qd_entity_t *entity)
             QD_ERROR_BREAK();
         }
 
-        //
-        // Obtain the log_source_lock lock. This lock is also used when write_log() is called.
-        //
-        sys_mutex_lock(log_source_lock);
-
-        qd_log_source_t *src = qd_log_source_lh(module); /* The original(already existing) log source */
+        qd_log_source_t *src = qd_log_source_find_or_make(module, false); /* The original (already existing) log source */
 
         if (has_output_file) {
+            sys_mutex_lock(log_source_lock);
             log_sink_t* sink = log_sink_lh(outputFile);
+            sys_mutex_unlock(log_source_lock);

Review comment:
       What prevents another thread from calling this function and freeing the same sink (line 618) once the first thread drops the lock?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org