Skip to content

Commit

Permalink
Ning null out responseStatus reference sooner
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonjkeller committed May 10, 2024
1 parent afda029 commit 6d12d7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -76,7 +77,6 @@ public void onThrowable(Throwable t) {
segment = null;
uri = null;
inboundHeaders = null;
responseStatus = null;
userAbortedOnStatusReceived = null;
}
Weaver.callOriginal();
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -73,7 +74,6 @@ public void onThrowable(Throwable t) {
segment = null;
uri = null;
inboundHeaders = null;
responseStatus = null;
userAbortedOnStatusReceived = null;
}
Weaver.callOriginal();
Expand All @@ -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();
Expand All @@ -102,23 +105,21 @@ 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;
}

return Weaver.callOriginal();
}

private Integer getStatusCode() {
if (responseStatus != null)
{
if (responseStatus != null) {
return responseStatus.getStatusCode();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -73,7 +74,6 @@ public void onThrowable(Throwable t) {
segment = null;
uri = null;
inboundHeaders = null;
responseStatus = null;
userAbortedOnStatusReceived = null;
}
Weaver.callOriginal();
Expand All @@ -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();
Expand All @@ -102,23 +105,21 @@ 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;
}

return Weaver.callOriginal();
}

private Integer getStatusCode() {
if (responseStatus != null)
{
if (responseStatus != null) {
return responseStatus.getStatusCode();
}
return null;
Expand Down

0 comments on commit 6d12d7d

Please sign in to comment.