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

rcmgr: Finish reservation in one place when connection handshake fails #2033

Closed
MarcoPolo opened this issue Jan 31, 2023 · 0 comments · Fixed by #2037
Closed

rcmgr: Finish reservation in one place when connection handshake fails #2033

MarcoPolo opened this issue Jan 31, 2023 · 0 comments · Fixed by #2037

Comments

@MarcoPolo
Copy link
Collaborator

The correct flow when negotiating a connection is:

  1. Get a connection reservation.
  2. Handshake/negotiate the connection.
  3. On error, finish the reservation.
  4. On success return a connection that will finish the reservation on connection .Close().

Currently for step 3, we are finishing the reservation in multiple code paths. This is error prone since it's easy to forget to finish a reservation somewhere and have a connection reservation leak. See #2025 for an example.

The fix here is to refactor the code so that the on error step always happens. The two approaches are to either:

  1. Wrap the logic in another function, and finish the reservation by the caller on error.
  2. Handle the error in a defer func (aka err defer).

1 is probably more idiomatic Go code, so prefer that.

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.

1 participant