Skip to content

Close ReactiveSocket on DuplexConnection close. #128

@NiteshKant

Description

@NiteshKant

Problem

Today, ReactiveSocket does not know when the underlying DuplexConnection is closed. This has two problems:

  • The underlying connection close is only discovered on writing a KeepAlive frame or writing/reading other frames. Although this "works" but is not ideal as that means we have to wait till the KeepAlive duration or next write to know about something that is easily available from the transport layer.
  • There is currently no way of notifying a user when a ReactiveSocket closes. onShutdown() only handles explicit shutdown() calls.

Proposal

We can add two methods to ReactiveSocket, viz.,

    /**
     * Close this {@code ReactiveSocket} upon subscribing to the returned {@code Publisher}
     *
     * <em>This method is idempotent and hence can be called as many times at any point with same outcome.</em>
     *
     * @return A {@code Publisher} that completes when this {@code ReactiveSocket} close is complete.
     */
    Publisher<Void> close();

and

    /**
     * Returns a {@code Publisher} that completes when this {@code ReactiveSocket} is closed. A {@code ReactiveSocket}
     * can be closed by explicitly calling {@link #close()} or when the underlying transport connection is closed.
     *
     * @return A {@code Publisher} that completes when this {@code ReactiveSocket} close is complete.
     */
    Publisher<Void> closeNotifier();

The above can replace the following methods that currently exist:

void onShutdown(Completable c);
void shutdown();
void close() throws Exception;

Same methods will be added to DuplexConnection thus wiring close() together and providing correct notifications to users when the ReactiveSocket is closed.

We can modify onShutdown() and shutdown() methods to the signature of my proposal but I think close() is more inline with other implementations of connections found elsewhere.

Current close() method is inherited from AutoCloseable which signifies synchronous execution as it return void.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions