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

"java.io.IOException: Remotely closed" in HTTPS (AHC) #1939

Closed carryel closed 7 years ago

carryel commented 7 years ago

I use Grizzly 2.3.30 + AHC 1.9.40.

When the HTTPS Server didn't support Keep-Alive(connection=close), the grizzly http client(AHC) failed to parse the last packet of response.

java.util.concurrent.ExecutionException: java.io.IOException: Remotely closed
    at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerGet(SafeFutureImpl.java:349)
    at org.glassfish.grizzly.impl.SafeFutureImpl.get(SafeFutureImpl.java:255)
    at com.ning.http.client.providers.grizzly.GrizzlyResponseFuture.get(GrizzlyResponseFuture.java:127)

When I debug the SSLBaseFilter#unwrapAll, I could see some strange status of buffers.

https://github.com/javaee/grizzly/blob/2.3.x/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java#L432 and https://github.com/javaee/grizzly/blob/2.3.x/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java#L436

https://github.com/javaee/grizzly/blob/2.3.x/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java#L423

https://github.com/javaee/grizzly/blob/2.3.x/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java#L465

I think SSLEngine already read the last packet(result.output) but local output didn't be assigned in SSL termination because of https://github.com/javaee/grizzly/blob/2.3.x/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java#L436.

Unfortunately, I couldn't reproduce it with simple testcase but sometimes I met it in production environment.

carryel commented 7 years ago

When I tried to fix it simply like this(https://github.com/carryel/grizzly/blob/2.3.x/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java#L423L445), I didn't met the error.

rlubke commented 7 years ago

@carryel Could you create a pull request?

carryel commented 7 years ago

@rlubke Sure. I just create a PR. https://github.com/javaee/grizzly/pull/1940

rlubke commented 7 years ago

@carryel I've merged the PR. I'll take care of porting to 2.4.x and master.

carryel commented 7 years ago

@rlubke Thanks! Perhaps could I know when the next release of 2.3.x will be able?

rlubke commented 7 years ago

@carryel Most likely by the end of the week.

rlubke commented 7 years ago

@carryel I'm not sure if you've subscribed to the new discussion group, but 2.3.31 has been released.

carryel commented 7 years ago

@rlubke Thanks a lot. I already subscribed. :-)