Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionObserver: provide ConnectionInfo on transport handshake #2726

Merged

Conversation

idelpivnitskiy
Copy link
Member

@idelpivnitskiy idelpivnitskiy commented Oct 6, 2023

Motivation:

If connection fails with an exception before one of the "established" methods were invoked, users don't have access to meaningful information, like SslConfig, SocketOptions, channelId (for correlation with wire logs), local address, etc.

Modifications:

  • Add ConnectionObserver.onTransportHandshakeComplete(ConnectionInfo) callback that gives users a ST view of the netty's Channel;
  • Deprecate pre-existing ConnectionObserver.onTransportHandshakeComplete();

Results:

  1. Users can collect more information about a connection if it's failed before "established".
  2. Users can get Channel's ID for reporting ProxyConnectObserver events and security handshake failures.

Motivation:

If connection fails with an exception before one of the "established"
methods were invoked, users don't have access to meaningful information,
like `SslConfig`, SocketOptions, channelId (for correlation with wire
logs), etc.

Modifications:

- Add `ConnectionObserver.onConnectionInitialization(ConnectionInfo)`
callback that gives users a ST view of the netty's `Channel`;

Results:

1. Users can collect more information about a connection if it's failed
before "established".
2. Users can get Channel's ID for reporting `ProxyConnectObserver`
events.
@idelpivnitskiy idelpivnitskiy self-assigned this Oct 6, 2023
* Finalized {@link ConnectionInfo} will be available via {@link #connectionEstablished(ConnectionInfo)} or
* {@link #multiplexedConnectionEstablished(ConnectionInfo)} callbacks.
*/
default void onConnectionInitialization(ConnectionInfo info) { // FIXME: 0.43 - consider removing default impl
Copy link
Member Author

Choose a reason for hiding this comment

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

Open for better name ideas

Copy link
Member Author

Choose a reason for hiding this comment

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

The trick is that at this point channel.localAddress() and channel.remoteAddress() return null. This is not aligned with ConnectionInfo API (non-nullable methods). Another option is to provide onTransportHandshakeComplete(ConnectionInfo) instead of onTransportHandshakeComplete(). When Channel becomes active, addresses are available.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the naming for other events, they all use the past tense (failed, complete, established, etc.). So to align with the naming I would suggest onConnectionInitialized

I see that you want to convey that initialization just started, so what about onConnectionInitStarted ? (or onConnectionInitializationStarted but that is a bit long as well)

Copy link
Member Author

Choose a reason for hiding this comment

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

As we discussed offline, changing to onTransportHandshakeComplete(ConnectionInfo)

* Finalized {@link ConnectionInfo} will be available via {@link #connectionEstablished(ConnectionInfo)} or
* {@link #multiplexedConnectionEstablished(ConnectionInfo)} callbacks.
*/
default void onConnectionInitialization(ConnectionInfo info) { // FIXME: 0.43 - consider removing default impl
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the naming for other events, they all use the past tense (failed, complete, established, etc.). So to align with the naming I would suggest onConnectionInitialized

I see that you want to convey that initialization just started, so what about onConnectionInitStarted ? (or onConnectionInitializationStarted but that is a bit long as well)

* Finalized {@link ConnectionInfo} will be available via {@link #connectionEstablished(ConnectionInfo)} or
* {@link #multiplexedConnectionEstablished(ConnectionInfo)} callbacks.
*/
default void onConnectionInitialization(ConnectionInfo info) { // FIXME: 0.43 - consider removing default impl
Copy link
Contributor

Choose a reason for hiding this comment

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

If the ConnectionInfo has too much that we can offer, maybe we should revisit the discussed concept of a ReducedConnectionInfo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Context for others from our offline discussion:

I thought about that as well, but because EarlyConnectionAcceptor already uses ConnectionInfo and it's a FunctionalInterface, didn't want to create inconsistency. Propagation of ExecutionContext makes it harder indeed. I was less worried, bcz officially it's "internal" API, changes for initializers should not be visible for users in practice.

@idelpivnitskiy idelpivnitskiy changed the title ConnectionObserver: provide ConnectionInfo when initialization starts ConnectionObserver: provide ConnectionInfo on transport handshake Oct 6, 2023
@idelpivnitskiy
Copy link
Member Author

@daschl, resolved all comments based on our discussion. I will merge this bcz I need it as a snapshot. Please review the final changes, I will submit a follow-up PR if you have comments.

@idelpivnitskiy idelpivnitskiy merged commit 4fb2ac1 into apple:main Oct 6, 2023
15 checks passed
@idelpivnitskiy idelpivnitskiy deleted the onConnectionInitialization branch October 6, 2023 22:05
@daschl
Copy link
Contributor

daschl commented Oct 9, 2023

@daschl, resolved all comments based on our discussion. I will merge this bcz I need it as a snapshot. Please review the final changes, I will submit a follow-up PR if you have comments.

LGTM 👍

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.

None yet

2 participants