javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
222 stars 60 forks source link

Exception thrown when sending request through proxy and receiving a close #1923

Closed afelisatti closed 7 years ago

afelisatti commented 7 years ago

We have a grizzly provider set up to use a proxy to hit an HTTPS server. We can see the CONNECT being successful and the request start being processed. However, when it's done an "HTTP keep-alive was disabled for this connection" exception is thrown, causing the Future awaiting the response to fail. This only occurs when the server responds with a "Connection: close" header. We have found this was working in version 1.9.31 but broke somewhere in between 1.9.39. The change seems to be in line 103 of HttpTransactionContext which added the abort:

        @Override
        public void onClosed(Closeable closeable, CloseType type) throws IOException {
            if (isGracefullyFinishResponseOnClose()) {
                // Connection was closed.
                // This event is fired only for responses, which don't have
                // associated transfer-encoding or content-length.
                // We have to complete such a request-response processing gracefully.
                final FilterChain fc = (FilterChain) connection.getProcessor();
                fc.fireEventUpstream(connection,
                        new GracefulCloseEvent(HttpTransactionContext.this), null);
            } else if (CloseType.REMOTELY.equals(type)) {
                abort(AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION);
            } else {
                try {
                    closeable.assertOpen();
                } catch (IOException ioe) {
                    // unwrap the exception as it was wrapped by assertOpen.
                    abort(ioe.getCause());
                }
            }
        }
    };
rlubke commented 7 years ago

Tracking here: https://github.com/javaee/grizzly-ahc/issues/2