Skip to content

Wait for the server ack when leaving channels - #6792

Open
patric-vinicios wants to merge 1 commit into
phoenixframework:mainfrom
patric-vinicios:fix-channel-leave-ack
Open

Wait for the server ack when leaving channels#6792
patric-vinicios wants to merge 1 commit into
phoenixframework:mainfrom
patric-vinicios:fix-channel-leave-ack

Conversation

@patric-vinicios

Copy link
Copy Markdown
Contributor

I ran into this while looking at channel cleanup in an app

leave() was returning "ok" before the server had actually replied.

leave() changes the channel state to leaving and then checks canPush(), but canPush() only returns true when the channel is still joined so at that point it always returns false

Then, the fallback runs right away and the channel closes locally instead of waiting for the server reply or the leave timeout

The fix is just to check canPush() before changing the state to leaving

If the channel can still push, it sends the leave request and waits for either the reply or the timeout. If it cant, it keeps the existing behavior and closes immediately

I also re-enabled the tests for the leaving state and leave timeout

Tested with:

  • npm test -- --runInBand
  • npx eslint assets/js/phoenix/channel.js assets/test/channel_test.js

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.

1 participant