Repository navigation
fix: check the pthread return values in builds that ship - #369
Merged
Merged
Conversation
consumer.c checked them with assert(), and NDEBUG is defined in Release, RelWithDebInfo and MinSizeRel -- the builds people actually install. So the return values were examined in development and nowhere else, which is the part of HardySimpson#357 that holds up. ZC_PTHREAD_CHECK() reports through zc_error() instead, in every build. It covers the ten assert sites and eight calls that were not checked at all: the lock, wait and unlock around the consumer's wakeup condition, the pair around the flush wait, and both ends of log_consumer_queue_reserve(). Reporting is the honest maximum. On a correctly initialised normal mutex these fail with EINVAL or EDEADLK, which means corrupted memory or a programming error; there is no state a logging library can restore, so it says what happened and leaves the application running rather than pretending to recover. The cost is a branch on a path already paying for a mutex, and the strings prove the checks are there: $ strings consumer.c.o | grep 'pthread.*fail' pthread_mutex_lock(&logc->event.siglock) fail, rc[%d] ... from the -DNDEBUG build. 38/38 tests pass in Debug, 36/36 in Release, and the consumer and multithread tests are clean under ThreadSanitizer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
consumer.c checked them with assert(), and NDEBUG is defined in Release, RelWithDebInfo and MinSizeRel -- the builds people actually install. So the return values were examined in development and nowhere else, which is the part of #357 that holds up.
ZC_PTHREAD_CHECK() reports through zc_error() instead, in every build. It covers the ten assert sites and eight calls that were not checked at all: the lock, wait and unlock around the consumer's wakeup condition, the pair around the flush wait, and both ends of log_consumer_queue_reserve().
Reporting is the honest maximum. On a correctly initialised normal mutex these fail with EINVAL or EDEADLK, which means corrupted memory or a programming error; there is no state a logging library can restore, so it says what happened and leaves the application running rather than pretending to recover.
The cost is a branch on a path already paying for a mutex, and the strings prove the checks are there:
from the -DNDEBUG build. 38/38 tests pass in Debug, 36/36 in Release, and the consumer and multithread tests are clean under ThreadSanitizer.