iamsanjay commented on PR #2876: URL: https://github.com/apache/solr/pull/2876#issuecomment-2774697417
We're hitting a NullPointerException in async code when calling TraceUtils.getSpan(req) after upgrading to Jetty 12. The root cause is that Jetty 12 no longer guarantees that ServletApiRequest.getRequest() will return a non-null value once the request crosses an async boundary (e.g., background threads, ExecutorService, etc.). In Solr, we set the tracing Span on the HttpServletRequest early in the request lifecycle (in traceHttpRequestExecution2()), and later retrieve it using TraceUtils.getSpan(req). This worked fine in Jetty 9–11, but in Jetty 12, calling getSpan(req) from async code can throw NPEs because the internal Jetty Request is gone. ### Fix To avoid this, we now cache the span inside HttpSolrCall during its construction, which happens synchronously and before any async processing starts. This ensures we capture the span while the Jetty request is still valid: ``` public HttpSolrCall(HttpServletRequest req, ...) { this.span = Optional.ofNullable(TraceUtils.getSpan(req)).orElse(Span.getInvalid()); } ``` All downstream code — including async paths like processAndWait() or CoreAdminHandler — now reads the cached Span from the HttpSolrCall instance rather than trying to access it from the request again. This avoids the NPE and keeps tracing safe and Jetty 12–compliant without needing to propagate servlet context manually. (Powered by ChatGPT! 🤖) It would be great if someone else also confirms this theory — hahaha! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org