Skip to content

Commit

Permalink
Move registration to terminate event outside of doFinally when we hav…
Browse files Browse the repository at this point in the history
…e the real connection

Obtain the event loop outside of doFinally when we have the real connection
  • Loading branch information
violetagg committed Oct 7, 2024
1 parent 68f0b2a commit 4962698
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2020-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -266,27 +266,25 @@ static final class TracingMapHandle implements BiFunction<Mono<Void>, Connection
public Mono<Void> apply(Mono<Void> voidMono, Connection connection) {
HttpServerRequest braveRequest = connection.channel().attr(REQUEST_ATTR_KEY).get();
Span span = connection.channel().attr(SPAN_ATTR_KEY).get();
connection.onTerminate()
.subscribe(
null,
t -> cleanup(connection.channel()),
() -> cleanup(connection.channel()));
EventLoop eventLoop = connection.channel().eventLoop();
return voidMono.doFinally(sig -> {
if (braveRequest.unwrap() instanceof reactor.netty.http.server.HttpServerResponse) {
reactor.netty.http.server.HttpServerResponse response =
(reactor.netty.http.server.HttpServerResponse) braveRequest.unwrap();
Span localSpan = sig == SignalType.CANCEL ? span.annotate("cancel") : span;
HttpServerResponse braveResponse =
new DelegatingHttpResponse(response, braveRequest, throwable);
response.withConnection(conn -> {
conn.onTerminate()
.subscribe(
null,
t -> cleanup(connection.channel()),
() -> cleanup(connection.channel()));
EventLoop eventLoop = conn.channel().eventLoop();
if (eventLoop.inEventLoop()) {
handler.handleSend(braveResponse, localSpan);
}
else {
eventLoop.execute(() -> handler.handleSend(braveResponse, localSpan));
}
});
if (eventLoop.inEventLoop()) {
handler.handleSend(braveResponse, localSpan);
}
else {
eventLoop.execute(() -> handler.handleSend(braveResponse, localSpan));
}
}
})
.doOnError(this::throwable)
Expand Down

0 comments on commit 4962698

Please sign in to comment.