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

[ECO-4687][Protocol-2] Fix duplicate outgoing ATTACH msg #416

Merged

Conversation

sacOO7
Copy link
Contributor

@sacOO7 sacOO7 commented Jun 24, 2024

Main issue was related to the fact that, every msg that needs to be sent is queued first in the global queue and then sent one by one. Since, protocol 2 supports sending force ATTACH on every connected msg, if there is existing ATTACH in queue, both of the ATTACH will be sent on CONNECTED -> https://github.com/ably/specification/pull/193/files

Fixed ably-ruby implementation responsible for sending duplicate ATTACH message.

  1. Send attach only when connection state is CONNECTED
  2. Do not queue the attach message, instead send immediately on connected
  3. Removed use of emitter pattern while clearing attach/detach timers (see Improper use of EventEmitter [violation of RTC10] #413)

Link to internal discussion
https://ably-real-time.slack.com/archives/C8SPU4589/p1718275991214299?thread_ts=1718115075.720879&cid=C8SPU4589 ( check for last few messages regarding decision taken )

PS. It will be easy to understand changes by going through each commit.

1. Send attach only when connection state is CONNECTED
2. Not queue attach message, instead send is immediately on connected
3. Removed use of emitter pattern while clearing attach/detach timers
@github-actions github-actions bot temporarily deployed to staging/pull/416/features June 24, 2024 11:20 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/416/docs June 24, 2024 11:20 Inactive
@sacOO7 sacOO7 marked this pull request as ready for review June 24, 2024 11:24
@sacOO7 sacOO7 changed the title Fix duplicate msg send [ECO-4687][Protocol-2] Fix duplicate msg send Jun 24, 2024
@sacOO7 sacOO7 changed the title [ECO-4687][Protocol-2] Fix duplicate msg send [ECO-4687][Protocol-2] Fix duplicate outgoing ATTACH msg Jun 24, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/416/features July 2, 2024 11:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/416/docs July 2, 2024 11:34 Inactive
1. Moved sending ATTACH msg as a part of separate codebase
2. DETEACH msg will be re-attempted on reconnection if pending timer exist
3. notify_state_change made accessible to channel_state_machine
@github-actions github-actions bot temporarily deployed to staging/pull/416/features July 2, 2024 13:06 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/416/docs July 2, 2024 13:06 Inactive
@sacOO7
Copy link
Contributor Author

sacOO7 commented Jul 2, 2024

I have updated implementation for sending ATTACH and DETACH msg to be separate as a part of 8b9b556.
Earlier, most of the code was DETACH specific and had nothing to do with sending ATTACH message.

@lawrence-forooghian
Copy link
Collaborator

I've tried taking a look at this PR but it's quite complicated and I don't really understand what's going on. Might be best to have a call about it.

@lawrence-forooghian
Copy link
Collaborator

Recapping our call:

  • let's move the connection state check to #attach per RTL4i, then we won't need this new force_attach flag
  • the final commit is just a refactor; splits the attach and detach logic (which deviated further in the first commit) into separate methods instead of a shared method
  • I asked whether we need some new tests? Sachin said he'd look into it
  • I still don't understand the notify_state_change method, or what it has to do with Improper use of EventEmitter [violation of RTC10] #413, or what Improper use of EventEmitter [violation of RTC10] #413 has to do with this issue; we need to have another conversation about that

Base automatically changed from feature/protocol-2-resume-recover to feature/integration-protocol-2 July 3, 2024 11:48
@github-actions github-actions bot temporarily deployed to staging/pull/416/features July 4, 2024 07:31 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/416/docs July 4, 2024 07:31 Inactive
1. marked notify_state_change as accessible
2. annotated code with right spec ids
@sacOO7 sacOO7 force-pushed the fix/duplicate-attach-msg-send branch from 50395de to 07aadbd Compare July 4, 2024 07:52
@github-actions github-actions bot temporarily deployed to staging/pull/416/features July 4, 2024 07:52 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/416/docs July 4, 2024 07:53 Inactive
@sacOO7
Copy link
Contributor Author

sacOO7 commented Jul 4, 2024

Recapping our call:

  • let's move the connection state check to #attach per RTL4i, then we won't need this new force_attach flag
  • the final commit is just a refactor; splits the attach and detach logic (which deviated further in the first commit) into separate methods instead of a shared method
  • I asked whether we need some new tests? Sachin said he'd look into it
  • I still don't understand the notify_state_change method, or what it has to do with Improper use of EventEmitter [violation of RTC10] #413, or what Improper use of EventEmitter [violation of RTC10] #413 has to do with this issue; we need to have another conversation about that
  • I have removed use of forced_attach from the code and added connected check while calling attach explicitly.
  • Added test to make sure no ATTACH/ATTACHED duplicates SENT/RECEIVED -> 47c55d7
  • About notify_state_change, it is introduced to replace ->
    channel.once_state_changed do
    @pending_state_change_timer.cancel if @pending_state_change_timer
    @pending_state_change_timer = nil
    end
    .
  • As, you can see
        channel.once_state_changed do
          @pending_state_change_timer.cancel if @pending_state_change_timer
          @pending_state_change_timer = nil
        end

is registering a callback on emitter class, same is used to register callbacks externally
e.g.

    channel.attach do
       # does some stuff for longer time
    end
  • All of these callbacks gets executed in the order they are registered. You can see the callback array ->
    callbacks_any << proc_block
    and it gets executed in a for loop ->
    [callbacks_any, callbacks[callbacks_event_coerced(event_name)]].each do |callback_arr|
  • So, if we first register a external callback that does work for long time, the callback responsible for cancelling timer won't execute. Hence, it will put channel into suspended state.
  • This is a one of the problem described as per RTC10 ( do read related spec )
  • So, this is a small fix done to avoid sending duplicate ATTACH message, since getting into suspended state again triggers reattach mechanism as per RTL4f
    after_transition(to: [:suspended]) do |channel, current_transition|
    channel.manager.start_attach_from_suspended_timer
    end

@sacOO7 sacOO7 merged commit 9981082 into feature/integration-protocol-2 Jul 4, 2024
3 of 23 checks passed
@sacOO7 sacOO7 deleted the fix/duplicate-attach-msg-send branch July 4, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants