Browse Source

Handle response correctly when request already cancelled (#110249)

Related to #109866
Nick Tindall 1 year ago
parent
commit
6f72d4ccaa

+ 5 - 1
modules/transport-netty4/src/internalClusterTest/java/org/elasticsearch/http/netty4/Netty4ChunkedContinuationsIT.java

@@ -646,7 +646,11 @@ public class Netty4ChunkedContinuationsIT extends ESNetty4IntegTestCase {
                                 client.execute(TYPE, new Request(), new RestActionListener<>(channel) {
                                     @Override
                                     protected void processResponse(Response response) {
-                                        localRefs.mustIncRef();
+                                        // incRef can fail if the request was already cancelled
+                                        if (localRefs.tryIncRef() == false) {
+                                            assert localRefs.hasReferences() == false : "tryIncRef failed but RefCounted not completed";
+                                            return;
+                                        }
                                         channel.sendResponse(RestResponse.chunked(RestStatus.OK, response.getResponseBodyPart(), () -> {
                                             // cancellation notification only happens while processing a continuation, not while computing
                                             // the next one; prompt cancellation requires use of something like RestCancellableNodeClient