You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HttpsUrlConnections hang (then respond correctly) when setUseEngineSocket is true #433
When setUseEngineSocket is false, things work great.
When setUseEngineSocket is true, all requests using HttpsUrlConnection wait exactly 60 seconds, then respond with the expected 200 response.
I finally got a chance to diagnose this and it looks like it's due to HTTP keep-alive combined with the lack of nonblocking I/O on InputStream. The peer doesn't close the socket for 60 seconds because of HTTP keep-alive. If we happen to give a buffer to InputStream.read() that's larger than the entire encrypted stream, it will block until the buffer is full or the socket is closed, which means it waits until the keep-alive times out.
There are a couple ways we could try to work around this.
We could try to read only a single byte from the socket (which will block), and when that returns, check how many bytes are available and just read those. That will probably eliminate a bunch of the situations where this blocks needlessly, but relies on available() working, which isn't guaranteed.
We also could use non-blocking Channels, which requires us to not rely on Socket's underlying connection machinery and instead create our own SocketChannel and connect that. It won't work when we're asked to wrap an existing Socket.
I'm going to start with the first one and see if that'll work.
Actually, at this point, I'm not sure why the FD socket isn't taking 60 seconds to return. The same combination of factors applies there; just because we're reading the file descriptor directly shouldn't change anything, we're still being asked to just keep reading the file descriptor. Looking at a packet trace, though, the server sends a FIN immediately after finishing sending the HTTP response when it's dealing with the FD socket, but it waits for 60 seconds to do so when dealing with the engine socket, and which one we're using should be totally opaque to the server. Very curious.
@flooey if I add a Thread.sleep(..) to the testDefault() method then the FIN is not sent immediately. I'm thinking it's a consequence of the test ending and the VM being destroyed. What do you think?
It seems the Java implementation is using SocketInputStream as well. The difference that I see is with the Java implementation it appears to be reading SSL/TLS records (with well defined length) vs. Conscrypt which is just reading in a buffer. Is it possible to change Conscrypt to read record by record?
Activity
carterkozak commentedon Feb 28, 2018
Tagging folks who have been involved in this conversation: @nmittler @flooey @yschimke
carterkozak commentedon Mar 12, 2018
@nmittler @flooey Were you able to reproduce this issue? I'd be happy to provide assistance if you're running into issues.
nmittler commentedon Mar 12, 2018
@flooey mind taking a look?
flooey commentedon Mar 29, 2018
I finally got a chance to diagnose this and it looks like it's due to HTTP keep-alive combined with the lack of nonblocking I/O on InputStream. The peer doesn't close the socket for 60 seconds because of HTTP keep-alive. If we happen to give a buffer to InputStream.read() that's larger than the entire encrypted stream, it will block until the buffer is full or the socket is closed, which means it waits until the keep-alive times out.
There are a couple ways we could try to work around this.
We could try to read only a single byte from the socket (which will block), and when that returns, check how many bytes are available and just read those. That will probably eliminate a bunch of the situations where this blocks needlessly, but relies on available() working, which isn't guaranteed.
We also could use non-blocking Channels, which requires us to not rely on Socket's underlying connection machinery and instead create our own SocketChannel and connect that. It won't work when we're asked to wrap an existing Socket.
I'm going to start with the first one and see if that'll work.
flooey commentedon Mar 29, 2018
Actually, at this point, I'm not sure why the FD socket isn't taking 60 seconds to return. The same combination of factors applies there; just because we're reading the file descriptor directly shouldn't change anything, we're still being asked to just keep reading the file descriptor. Looking at a packet trace, though, the server sends a FIN immediately after finishing sending the HTTP response when it's dealing with the FD socket, but it waits for 60 seconds to do so when dealing with the engine socket, and which one we're using should be totally opaque to the server. Very curious.
dave-r12 commentedon Sep 10, 2018
@flooey if I add a
Thread.sleep(..)to thetestDefault()method then the FIN is not sent immediately. I'm thinking it's a consequence of the test ending and the VM being destroyed. What do you think?dave-r12 commentedon Sep 10, 2018
I'd love to see #65 get resolved. If there is anything I can do to help with that let me know.
I created a third test:
It seems the Java implementation is using
SocketInputStreamas well. The difference that I see is with the Java implementation it appears to be reading SSL/TLS records (with well defined length) vs. Conscrypt which is just reading in a buffer. Is it possible to change Conscrypt to read record by record?Fix implementation of available() in sockets
Fix implementation of available() in sockets (#694)