fix(undertow): null-check context key in UndertowActiveHandlers to prevent NPE#17559
fix(undertow): null-check context key in UndertowActiveHandlers to prevent NPE#17559divitsinghall wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
|
|
|
@divitsinghall were you able to reproduce the issue? Or have you managed to come up with an explanation why the counter is missing from the context? |
Thanks for reviewing! |
This is exactly what I'm interested in. Which code path passes context without the counter to these methods? I guess we can add the null check even if we don't understand why this happens, though it would be nice if we did. Perhaps the real bug is somewhere else. |
There was a problem hiding this comment.
the comment makes it look like context being not initialized is somehow expected
There was a problem hiding this comment.
I'm not convinced of the usefulness of this test
Summary
Fixes a possible NPE in
UndertowActiveHandlersreported in #16128.context.get(CONTEXT_KEY)can returnnullifinit()was never calledfor that context (e.g. in rare race conditions or atypical request flows).
Both
increment()anddecrementAndGet()previously dereferenced theresult without a null check, causing an NPE that failed real HTTP requests.
Occurs roughly once or twice per tens of millions of requests — rare but
impactful since it drops legitimate traffic.
Changes
increment(): no-op when counter is absent (counter was never initialized)decrementAndGet(): returns1when counter is absent, so callers thatcheck
== 0to end a span will safely skip that pathTests
Added
UndertowActiveHandlersTestcovering:increment()anddecrementAndGet()on an uninitialized context (the NPE paths)Fixes #16128