Add assertions that non-reentrant functions aren't called reentrantly #1591
+91
−4
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.
This is a draft version of this PR and is not ready to merge as-is. I'm opening it to get feedback on it before finishing the work.
While working on nodejs/node#38964 (and related question at #1590), I built this functionality in nghttp2_session.c to detect when the end-user of the library makes reentrant calls to nghttp2 from a callback in violation of the rules at https://nghttp2.org/documentation/programmers-guide.html#remarks. This was very helpful for me in verifying that I had correctly fixed the issue in node.js and thought it might be useful to have in nghttp2 DEBUGBUILDs.
As written, there are two different versions of this change.
at_callback_depth
.Option 1 uses a macro with some gcc extensions that I'm not sure are acceptable to the project.
Option 2 is much more prone to error now (as you need to make sure to track on each half of an if statement since the code tends to write
if (callback)
) and in the future as you need to remember to increment/decrementat_callback_depth
in new code.There's an option 3 that flattens some of the callback code to avoid the
if
issue. That is, changing:to this:
I should also note that my intention is for this code to only be active in DEBUGBUILDs but that is not done in the draft PR.
I'm happy to polish this up, but was looking for early feedback on the following:
Thanks!