Skip to content

fix: unify client shutdown around access point and dealer lifecycles#305

Open
gjermundgaraba wants to merge 1 commit intodevgianlu:masterfrom
gjermundgaraba:fix/audio-mercury-connection-lifecycle
Open

fix: unify client shutdown around access point and dealer lifecycles#305
gjermundgaraba wants to merge 1 commit intodevgianlu:masterfrom
gjermundgaraba:fix/audio-mercury-connection-lifecycle

Conversation

@gjermundgaraba
Copy link
Copy Markdown
Contributor

Follow-up to #302 and #303. Those PRs hardened the lifecycle of ap and dealer themselves, but they. This PR is targeting a downstream issue from this, which is that mercury.Client and audio.KeyProvider have no way to observe when pa dies (which can cause some issues, as you might imagine).

The approach I took here is one I can adjust, but essentially the design does two things:

  1. It makes ap the only things that truly closes
  2. It gives ap a single done signal for consumers (like mercury and audio) to rely on

The main benefit of this design is that it simplifies the life cycle a lot (for instance, session close can now just rely on ap closing instead of having to deal with all the consumers too).
The downside is that it is an API breaking change: mercury.Client.Close() and audio.KeyProvider.Close() are removed.

If you want to consider alternative designs, I am happy to do that. I have gone through some iterations on this, and in the end, I thought this was the cleanest.

General summary of the changes (🤖):

  • Unifies shutdown handling in Accesspoint and Dealer by replacing ad-hoc stop/closed flags with a shared done channel lifecycle.
  • Exposes Accesspoint.Done() and updates AP/dealer send/receive/reconnect loops to stop cleanly when shutting down.
  • Makes audio.KeyProvider and mercury.Client follow the access point lifecycle instead of maintaining their own separate close/stop channels.
  • Improves closed-state behavior for request/receive paths by returning ErrAccesspointClosed / ErrDealerClosed consistently and handling closed receiver channels safely.
  • Simplifies Session.Close() by removing redundant explicit closes for audio key / mercury clients and relying on AP shutdown ownership.
  • Adds regression tests covering clean ticker shutdown and request failures after the access point is closed.

@devgianlu
Copy link
Copy Markdown
Owner

I see your point and I like that it reduces the complexity overall. However, I am not fully sold on the fact that once a KeyProvider or MercuryClient is created it cannot be destroyed. This is not necessarely blocking for the merge, but something to take into consideration.

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