From 6d12d7de94e9657588539039eabe0dd11fad2eb8 Mon Sep 17 00:00:00 2001 From: Jason Keller Date: Fri, 10 May 2024 10:59:02 -0700 Subject: [PATCH] Ning null out responseStatus reference sooner --- .../asynchttpclient/NRAsyncHandler.java | 8 +++++--- .../asynchttpclient/NRAsyncHandler.java | 11 ++++++----- .../asynchttpclient/NRAsyncHandler.java | 11 ++++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/instrumentation/ning-async-http-client-1.0/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java b/instrumentation/ning-async-http-client-1.0/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java index 162ade5753..8e8c592489 100644 --- a/instrumentation/ning-async-http-client-1.0/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java +++ b/instrumentation/ning-async-http-client-1.0/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java @@ -65,6 +65,7 @@ public AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus) { } public void onThrowable(Throwable t) { + responseStatus = null; if (segment != null) { segment.reportAsExternal(GenericParameters .library("AsyncHttpClient") @@ -76,7 +77,6 @@ public void onThrowable(Throwable t) { segment = null; uri = null; inboundHeaders = null; - responseStatus = null; userAbortedOnStatusReceived = null; } Weaver.callOriginal(); @@ -103,6 +103,9 @@ public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) { @Trace(async = true) public T onCompleted() throws Exception { + Integer statusCode = getStatusCode(); + String reasonMessage = getReasonMessage(); + responseStatus = null; if (segment != null) { // This keeps the transaction alive after "segment.end()" just in case there are any completion handlers segment.getTransaction().getToken().linkAndExpire(); @@ -112,14 +115,13 @@ public T onCompleted() throws Exception { .uri(uri) .procedure("onCompleted") .inboundHeaders(inboundHeaders) - .status(getStatusCode(), getReasonMessage()) + .status(statusCode, reasonMessage) .build()); //This used to be segment.finish(t), but the agent doesn't automatically report t. segment.end(); segment = null; uri = null; inboundHeaders = null; - responseStatus = null; userAbortedOnStatusReceived = null; } diff --git a/instrumentation/ning-async-http-client-1.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java b/instrumentation/ning-async-http-client-1.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java index 309d9cb1cd..e836f8b1f7 100644 --- a/instrumentation/ning-async-http-client-1.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java +++ b/instrumentation/ning-async-http-client-1.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java @@ -62,6 +62,7 @@ public AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus) { } public void onThrowable(Throwable t) { + responseStatus = null; if (segment != null) { segment.reportAsExternal(GenericParameters .library("AsyncHttpClient") @@ -73,7 +74,6 @@ public void onThrowable(Throwable t) { segment = null; uri = null; inboundHeaders = null; - responseStatus = null; userAbortedOnStatusReceived = null; } Weaver.callOriginal(); @@ -93,6 +93,9 @@ public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) { @Trace(async = true) public T onCompleted() throws Exception { + Integer statusCode = getStatusCode(); + String reasonMessage = getReasonMessage(); + responseStatus = null; if (segment != null) { // This keeps the transaction alive after "segment.end()" just in case there are any completion handlers segment.getTransaction().getToken().linkAndExpire(); @@ -102,14 +105,13 @@ public T onCompleted() throws Exception { .uri(uri) .procedure("onCompleted") .inboundHeaders(inboundHeaders) - .status(getStatusCode(), getReasonMessage()) + .status(statusCode, reasonMessage) .build()); //This used to be segment.finish(t), but the agent doesn't automatically report t. segment.end(); segment = null; uri = null; inboundHeaders = null; - responseStatus = null; userAbortedOnStatusReceived = null; } @@ -117,8 +119,7 @@ public T onCompleted() throws Exception { } private Integer getStatusCode() { - if (responseStatus != null) - { + if (responseStatus != null) { return responseStatus.getStatusCode(); } return null; diff --git a/instrumentation/ning-async-http-client-1.6.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java b/instrumentation/ning-async-http-client-1.6.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java index 3826bae8ab..2680ec2e8a 100644 --- a/instrumentation/ning-async-http-client-1.6.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java +++ b/instrumentation/ning-async-http-client-1.6.1/src/main/java/com/nr/agent/instrumentation/asynchttpclient/NRAsyncHandler.java @@ -62,6 +62,7 @@ public AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus) { } public void onThrowable(Throwable t) { + responseStatus = null; if (segment != null) { segment.reportAsExternal(GenericParameters .library("AsyncHttpClient") @@ -73,7 +74,6 @@ public void onThrowable(Throwable t) { segment = null; uri = null; inboundHeaders = null; - responseStatus = null; userAbortedOnStatusReceived = null; } Weaver.callOriginal(); @@ -93,6 +93,9 @@ public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) { @Trace(async = true) public T onCompleted() throws Exception { + Integer statusCode = getStatusCode(); + String reasonMessage = getReasonMessage(); + responseStatus = null; if (segment != null) { // This keeps the transaction alive after "segment.end()" just in case there are any completion handlers segment.getTransaction().getToken().linkAndExpire(); @@ -102,14 +105,13 @@ public T onCompleted() throws Exception { .uri(uri) .procedure("onCompleted") .inboundHeaders(inboundHeaders) - .status(getStatusCode(), getReasonMessage()) + .status(statusCode, reasonMessage) .build()); // This used to be segment.finish(t), but the agent doesn't automatically report it. segment.end(); segment = null; uri = null; inboundHeaders = null; - responseStatus = null; userAbortedOnStatusReceived = null; } @@ -117,8 +119,7 @@ public T onCompleted() throws Exception { } private Integer getStatusCode() { - if (responseStatus != null) - { + if (responseStatus != null) { return responseStatus.getStatusCode(); } return null;