Skip to content

Fix polling ares_event_configchg_init: initialize mutex - #974

Merged
bradh352 merged 1 commit into
c-ares:mainfrom
FlorianPfisterer:main
Apr 8, 2025
Merged

Fix polling ares_event_configchg_init: initialize mutex#974
bradh352 merged 1 commit into
c-ares:mainfrom
FlorianPfisterer:main

Conversation

@FlorianPfisterer

Copy link
Copy Markdown
Contributor

The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.
@bradh352

Copy link
Copy Markdown
Member

thanks, interesting this mutex initialization was missed. Guess this wasn't well tested on platforms outside of Windows/Linux/MacOS since none of those use this polling logic.

@bradh352

bradh352 commented Apr 5, 2025

Copy link
Copy Markdown
Member

If you update your branch the CI builds should work.

@bradh352
bradh352 merged commit 42c9d9d into c-ares:main Apr 8, 2025
bradh352 pushed a commit that referenced this pull request Apr 8, 2025
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
bradh352 pushed a commit that referenced this pull request Apr 8, 2025
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
bradh352 pushed a commit that referenced this pull request Apr 8, 2025
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
bradh352 pushed a commit that referenced this pull request Apr 8, 2025
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
bradh352 pushed a commit that referenced this pull request Apr 8, 2025
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
@FlorianPfisterer

Copy link
Copy Markdown
Contributor Author

Thanks for merging @bradh352!

michael-dev pushed a commit to HamelinPorts/android_external_c-ares that referenced this pull request Apr 25, 2026
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
michael-dev pushed a commit to HamelinPorts/android_external_c-ares that referenced this pull request Apr 25, 2026
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
michael-dev pushed a commit to HamelinPorts/android_external_c-ares that referenced this pull request Apr 25, 2026
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
michael-dev pushed a commit to HamelinPorts/android_external_c-ares that referenced this pull request Apr 25, 2026
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
michael-dev pushed a commit to HamelinPorts/android_external_c-ares that referenced this pull request Apr 25, 2026
The polling-based implementation of ares_event_configchg_init previously
did not initialize the mutex ares_event_configchg_t->lock. This caused
ares_thread_cond_timedwait to immediately return, which means that the
thread running ares_event_configchg_thread is busy-waiting without
sleeping between config change checks. In addition to the high CPU usage
this causes, the DNS config is actually never checked in this case.

This commit fixes the issue by initializing the mutex. Thereby, the
config polling thread correctly only wakes up every 30 seconds and
properly checks for a config change.

Note: the bug only came into effect if the combination of the polling-
based implementation of ares_event_configchg_init and the pthread-based
implementation of ares_thread_cond_timedwait was used.

Fix By: Florian Pfisterer (@FlorianPfisterer)
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.

2 participants