Skip to content

Commit

Permalink
Merge pull request #2510 from csalve/fix-missing-mutex-for-next_msg_out
Browse files Browse the repository at this point in the history
fix data race mosquitto_loop function
  • Loading branch information
ralight committed Apr 29, 2022
2 parents 0745a85 + 4077987 commit 82dff0f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
}

now = mosquitto_time();
pthread_mutex_lock(&mosq->msgtime_mutex);
if(mosq->next_msg_out && now + timeout_ms/1000 > mosq->next_msg_out){
timeout_ms = (mosq->next_msg_out - now)*1000;
}
pthread_mutex_unlock(&mosq->msgtime_mutex);

if(timeout_ms < 0){
/* There has been a delay somewhere which means we should have already
Expand Down

0 comments on commit 82dff0f

Please sign in to comment.