Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jdk11 http client so that segments don't time out #1053

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

jasonjkeller
Copy link
Contributor

Fixes a bug that would cause a segment timeout in the JDK 11 HTTP client instrumentation. The bug would occur whenever the synchronous HttpClient.send(...) method was invoked and any exception other than a ConnectException was thrown.

If an exception occurred here we would call handleConnectException:

    @Trace
    public <T> HttpResponse<T> send(HttpRequest req, HttpResponse.BodyHandler<T> responseHandler)
            throws IOException, InterruptedException {
        URI uri = req.uri();
        Segment segment = startSegment(uri);
        HttpResponse<T> response;
        try {
            response = Weaver.callOriginal();
            if (segment == null) {
                return response;
            }
        } catch (Exception e) {
            handleConnectException(e, req, segment);
            throw e;
        }
        processResponse(response, segment);
        return response;
    }

If the exception was a ConnectException we would properly report it and end the segment but if it was any other exception type it only gets reported without actually ending the segment.

    public static void handleConnectException(Exception e, HttpRequest request, Segment segment){
        if (request.uri() != null) {
            if (throwableIsConnectException(e)) {
                reportUnknownHostExternal(segment);
            } else {
                NewRelic.noticeError(e);
                // FIXME we should be calling segment.end() in this case as well
            }
        }
    }

This would result in a segment for the external call hitting the 10 minute segment timeout limit and being truncated:
Screen Shot 2022-10-21 at 3 55 05 PM

After expiring the segment properly the segment completes in milliseconds and is no longer truncated:
Screen Shot 2022-10-21 at 3 56 12 PM

Copy link
Contributor

@tbradellis tbradellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty straight forward to me!

@jasonjkeller jasonjkeller merged commit debf9d7 into main Oct 24, 2022
@jasonjkeller jasonjkeller deleted the NR-0-fix-jdk11-http-client-bug branch October 24, 2022 16:26
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.

3 participants