Propagate Connection Closure to Client#64
Propagate Connection Closure to Client#64crazyrokr wants to merge 3 commits intoJavaSaBr:developfrom
Conversation
| protected void handleReceivedData(int receivedBytes, ByteBuffer readingBuffer) { | ||
| if (receivedBytes == -1) { | ||
| doHandshake(sslNetworkBuffer(), -1); | ||
| connection.close(); |
There was a problem hiding this comment.
it's not always about closing connection by my testing
There was a problem hiding this comment.
It's correct to close the connection in AbstractSslNetworkPacketReader when receivedBytes == -1.
In non-blocking I/O (which this library appears to use), a return value of -1 from a SocketChannel.read() call signifies that the connection has been gracefully closed by the remote peer (end-of-stream). If the local connection is not closed in response to this, it may leave the channel in an inconsistent or zombie state, potentially leading to resource leaks or repeated failed reads.
A test was added for this case: 6b19a97
There was a problem hiding this comment.
@crazyrokr I know about this, but I had many times during my own testing when it didn't work in this way
There was a problem hiding this comment.
In such case we have to create a test covering the mentioned scenario. If your statement is true, then the test linked above is invalid. Do you have any ideas on how to improve it to account for the scenario you mentioned?
This PR introduces the propagation of connection closures from the server to the client. Previously, clients might not have been correctly notified when a connection was closed by the server, potentially leading to stale connection states or unhandled exceptions in reactive streams.
Changes
ConnectionClosedExceptionto explicitly handle connection closure scenarios.AbstractConnectionto notify activeFluxSinksubscribers with aConnectionClosedExceptionwhen a connection is closed.AbstractNetworkPacketReaderandAbstractSslNetworkPacketReaderto correctly detect and report connection closures.ConnectionCloseTestto verify that the client correctly receives theConnectionClosedExceptionwhen a server connection is closed.