Skip to content

Propagate Connection Closure to Client#64

Open
crazyrokr wants to merge 1 commit intoJavaSaBr:developfrom
crazyrokr:propagate-connection-close
Open

Propagate Connection Closure to Client#64
crazyrokr wants to merge 1 commit intoJavaSaBr:developfrom
crazyrokr:propagate-connection-close

Conversation

@crazyrokr
Copy link
Copy Markdown
Contributor

@crazyrokr crazyrokr commented May 6, 2026

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

  • Added ConnectionClosedException to explicitly handle connection closure scenarios.
  • Updated AbstractConnection to notify active FluxSink subscribers with a ConnectionClosedException when a connection is closed.
  • Modified AbstractNetworkPacketReader and AbstractSslNetworkPacketReader to correctly detect and report connection closures.
  • Added a new unit test ConnectionCloseTest to verify that the client correctly receives the ConnectionClosedException when a server connection is closed.

activeSinks.add(sink);
sink.onDispose(() -> {
invalidPacketSubscribers.remove(listener);
activeSinks.remove(sink);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

}

protected void notifySinksOnError() {
if (activeSinks.isEmpty()) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use write lock here as well

protected void handleReceivedData(int receivedBytes, ByteBuffer readingBuffer) {
if (receivedBytes == -1) {
doHandshake(sslNetworkBuffer(), -1);
connection.close();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not always about closing connection by my testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants