Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double lock of lockRecv. #398

Merged
merged 1 commit into from
Mar 22, 2024
Merged

Conversation

philljj
Copy link
Contributor

@philljj philljj commented Mar 20, 2024

Description

If MqttClient_WaitType() returns early in a nonblock multithread build, the subsequent call to MqttReadStart() will double lock client->lockRecv because it was not checking if a partial read was already in progress.

Fixes ZD17513.

Testing

  • Build with --enable-stress, with CFLAGS="-DWOLFMQTT_NO_COND_SIGNAL" to use pure mutexes.
  • Force MqttClient_WaitType to return early, and used a simple lock tracking system to detect and abort on double locks.

Also can be reproduced with valgrind helgrind:

==28242== Thread #1: Attempt to re-lock a non-recursive lock I already hold
==28242==    at 0x484D633: mutex_lock_WRK (hg_intercepts.c:934)
==28242==    by 0x485278C: pthread_mutex_lock (hg_intercepts.c:960)
==28242==    by 0x4860293: wm_SemLock (mqtt_client.c:130)
==28242==    by 0x4860435: MqttReadStart (mqtt_client.c:301)
==28242==    by 0x4861133: MqttClient_WaitType (mqtt_client.c:1159)
==28242==    by 0x4861AAB: MqttClient_Connect (mqtt_client.c:1758)
==28242==    by 0x402EC9: multithread_test_init (multithread.c:363)
==28242==    by 0x403BDE: multithread_test (multithread.c:759)
==28242==    by 0x403F69: main (multithread.c:881)
==28242==  Lock was previously acquired
==28242==    at 0x484D70A: mutex_lock_WRK (hg_intercepts.c:944)
==28242==    by 0x485278C: pthread_mutex_lock (hg_intercepts.c:960)
==28242==    by 0x4860293: wm_SemLock (mqtt_client.c:130)
==28242==    by 0x4860435: MqttReadStart (mqtt_client.c:301)
==28242==    by 0x4861133: MqttClient_WaitType (mqtt_client.c:1159)
==28242==    by 0x4861AAB: MqttClient_Connect (mqtt_client.c:1758)
==28242==    by 0x402EC9: multithread_test_init (multithread.c:363)
==28242==    by 0x403BDE: multithread_test (multithread.c:759)
==28242==    by 0x403F69: main (multithread.c:881)

@philljj philljj self-assigned this Mar 20, 2024
@philljj philljj marked this pull request as draft March 20, 2024 19:58
@philljj philljj changed the title Fix thread errors, and add multirecv debug test. Fix double lock of lockRecv. Mar 21, 2024
@philljj philljj marked this pull request as ready for review March 21, 2024 02:31
@philljj philljj requested a review from embhorn March 21, 2024 03:07
Copy link
Member

@embhorn embhorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! Waiting on any other customer feedback before merging?

@philljj
Copy link
Contributor Author

philljj commented Mar 22, 2024

Customer is happy with these changes, not waiting on anything else.

@embhorn embhorn merged commit f9651ab into wolfSSL:master Mar 22, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants