Skip to content

Simplify ClientConnection implementation #2418

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

Closed
bernardnormier opened this issue Jan 2, 2023 · 6 comments · Fixed by #2600
Closed

Simplify ClientConnection implementation #2418

bernardnormier opened this issue Jan 2, 2023 · 6 comments · Fixed by #2600
Assignees
Milestone

Comments

@bernardnormier
Copy link
Member

    I still find the `ClientConnection` implementation too complex. 

To me, it should be a "simplified" connection cache implementation. It should keep track of the pending connect (_pendingConnectTask), the active connection (_activeConnection) and the background connection dispose count (_backgroundConnectionDisposeCount). No need for decorators.

Originally posted by @bentoi in #2396 (review)

@bernardnormier
Copy link
Member Author

ClientConnection, unlike ConnectionCache, serializes connections to the server and I believe it is a feature we should keep.

See also my blog: https://zeroc.atlassian.net/wiki/spaces/~bernard/blog/2023/01/02/1211039772/January+2+2023

@bernardnormier
Copy link
Member Author

I think the 2 decorators used for the implementation of ClientConnection are appropriate.

The ConnectProtocolConnectionDecorator makes sure we only InvokeAsync on a connected connection, even when:

  • the application calls ClientConnection.ConnectAsync concurrently (which would be dumb but allowed)
  • multiple ClientConnection.InvokeAsync are in progress

ConnectionCache is simpler in this respect because it does not need to worry about application code calling ConnectAsync.

The CleanupProtocolConnectionDecorator makes sure we ConnectAsync a connection only have the cleanup of the previous connection is completed. And in case we never call ConnectAsync on that connection, its DisposeAsync will await the cleanup of the previous connection.

ConnectionCache doesn't provide this connection serialization feature.

It's certainly possible to do the same without decorators but I doubt it would be simpler or clearer.

@bentoi
Copy link
Contributor

bentoi commented Jan 3, 2023

ClientConnection, unlike ConnectionCache, serializes connections to the server and I believe it is a feature we should keep.

It's not obvious to me why it's a feature we should keep, can you explain why?

@bernardnormier
Copy link
Member Author

The alternative - no serialization like ConnectionCache - would mean:

  • a single ClientConnection can generate N concurrent connections to the same Server
  • "N - 1" connections are "shutdown requested", shutting down or being disposed
  • we'd need to wait for all these shutdowns / disposes somewhere, presumably in ShutdownAsync and DisposeAsync

I think it's cleaner and clearer to serialize.

@bentoi
Copy link
Contributor

bentoi commented Jan 3, 2023

I find it's minor and it's still unclear to me why client connection / connection cache should behave differently in this respect.

@bernardnormier bernardnormier self-assigned this Jan 24, 2023
@bernardnormier
Copy link
Member Author

bernardnormier commented Jan 24, 2023

@bentoi is right, I will synchronize it with ConnectionCache together with #2566.

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 a pull request may close this issue.

3 participants