Skip to content

Lib is not re-sending pending messages on new transport after a resume #474

Closed

Description

@SimonWoolf

Log posted by a customer here (cf conversation) shows several issues:

  1. At one point it disconnects the transport for inactivity at 14:29:08.086Z, 16s after getting a detached from realtime at 14:28:52.151. That shouldn't happen.
  2. After it reconnects and resumes, it does not seem to be re-sending messages on the new transport that were pending on the previous transport, as required by RTN15f
  3. Related to the previous one: messages called back with a failure due to getting an ack for a higher msgSerial than the pending queue are called back with "Unknown error / 50000 / 500", which could be more informative

┆Issue is synchronized with this Jira Bug by Unito

Activity

  1. added
    bugSomething isn't working. It's clear that this does need to be fixed.
    on May 23, 2019
  2. paddybyers commented on Oct 30, 2019

    @paddybyers
    Member

    The customer log contains some sensitive information so we're not able to attach it here.

    However, I suggest that you start by creating a test for https://docs.ably.io/client-lib-development-guide/features/#RTN15f and see what happens, specifically relating to sending pending messages on a reestablished transport.

  3. self-assigned this
    on Oct 30, 2019
  4. amihaiemil commented on Oct 30, 2019

    @amihaiemil
    Contributor

    @paddybyers I did a little research and I landed on RealTimeResumeTest -- as far as I understand, this is where we should add the test you proposed. Am I right, or at least close to it? :D

  5. amihaiemil commented on Oct 31, 2019

    @amihaiemil
    Contributor

    @SimonWoolf This ticket is rather old, but maybe you remember about it. I'm new to the project and currently trying to figure out the architecture/concepts etc. From what I understand, by "transport" you actually mean "channel", right?

  6. paddybyers commented on Oct 31, 2019

    @paddybyers
    Member

    @SimonWoolf btw we discussed ^

  7. added 2 commits that reference this issue on Oct 31, 2019
  8. added 2 commits that reference this issue on Nov 4, 2019
  9. paddybyers commented on Jan 12, 2023

    @paddybyers
    Member

    The bug is here, clear as day: https://github.com/ably/ably-java/blob/main/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java#L1209

    Instead, queued messages should be reattempted, as per https://sdk.ably.com/builds/ably/specification/main/features/#RTN15c7

    The current behaviour originates from this commit: 3c7b2d0

  10. self-assigned this
    on Jan 12, 2023
  11. ikbalkaya commented on Jan 12, 2023

    @ikbalkaya
    Contributor

    @paddybyers If I am not mistaken, that particular code block refers to pendingMessages while spec talks about queuedMessages which is a different one. I'm trying to confirm that those queued messages are published after reconnection but I wanted to check whether I understand that point correctly.

  12. paddybyers commented on Jan 13, 2023

    @paddybyers
    Member

    There's a further problem with the handling of the failed resume case. The spec (https://sdk.ably.com/builds/ably/specification/main/features/#RTN15c7) says that existing channels transition to ATTACHING (and init a new attach sequence) if there is a new connection established. However, this library is transitioning all channels to SUSPENDED (https://sdk.ably.com/builds/ably/specification/main/features/#RTN15c7). This will also prevent pending messages from being reattempted after connection.

  13. paddybyers commented on Jan 13, 2023

    @paddybyers
    Member

    If I am not mistaken, that particular code block refers to pendingMessages while spec talks about queuedMessages which is a different one. I'm trying to confirm that those queued messages are published after reconnection but I wanted to check whether I understand that point correctly.

    There are two mechanisms implemented in ably-java.

    1. Queueing of messages in a Channel, if ClientOptions.queueMessages == true.
    2. Handling of pending messages in the ConnectionManager that have been sent and are awaiting acknowledgement.

    These are to meet two different requirements.

    I do think the spec is potentially confusing, but see https://sdk.ably.com/builds/ably/specification/main/features/#RTN19a1 - using the same queue is an implementation option, but ably-java does not do this.

    Nonetheless, the requirement is that messages in ConnectionManager.pendingMessages need to be reattempted on reconnection (whether the resume succeeded or not).

  14. SimonWoolf commented on Jan 13, 2023

    @SimonWoolf
    MemberAuthor
  15. ikbalkaya commented on Jan 13, 2023

    @ikbalkaya
    Contributor

    Thank you @SimonWoolf. I think we can use those changes to fix issues related to connection resumption here but we cannot directly use that branch. Since those changes target a different branch, which has a different project structure and has breaking changes in it we won't be able to merge this in the near future.

    But I am thinking of picking of changes from there and apply it to another branch that targets the main branch and then run @jaley's tests against those changes. I think this will probably be the quickest way to fix those resumption related issues without doing much work. WDYT? cc @paddybyers

  16. SimonWoolf commented on Jan 13, 2023

    @SimonWoolf
    MemberAuthor

    Since those changes target a different branch

    It shouldn't, base should be changed to main per ably/specification#119

    which has a different project structure

    What do you mean by this?

    and has breaking changes in it we won't be able to merge this in the near future.

    it has one breaking change, which per #868 should be made non-breaking before we merge it as a patch release

  17. ikbalkaya commented on Jan 13, 2023

    @ikbalkaya
    Contributor

    Before connection resumption / recovery changes there was another work to improve project structure. See #767 and Aka-protocol-2.0 branch is based on that. If I'm not mistaken the project restructure would cause breaking changes (class names, visibility etc) @QuintinWillison might shine more light on that but considering both PRs are on draft state, I do not think we can merge any of them soon.

    And yes, I'm aware of that spec change which made changes non-breaking but in java case I think the base branch will be breaking

  18. paddybyers commented on Jan 13, 2023

    @paddybyers
    Member

    @ikbalkaya I think using that branch as inspiration, and perhaps cherry-picking some of the code, would be a sensible way forward here

  19. ikbalkaya commented on Jan 16, 2023

    @ikbalkaya
    Contributor

    @paddybyers As I mentioned on the meeting that (https://sdk.ably.com/builds/ably/specification/main/features/#RTN15c7) point was added recently with protocol 2.0
    See : https://github.com/ably/specification/pull/88/files
    So instead I'm going to look into making the changes for older spec point (RTN15c2 ) but will just keep anything that fixes this particular issue without any additional features.

  20. ikbalkaya commented on Jan 16, 2023

    @ikbalkaya
    Contributor

    @SimonWoolf Sorry if that's not a question for you but I am a bit confused by this old spec point RTN15c3

    The client library should initiate an attach for channels that are in the @suspended@ state. For all channels in the @attaching@ or @attached@ state, the client library should initiate a new attach (i.e. a new @Attach@ @ProtocolMessage@ sent for each channel).

    My question is that what's the difference between a new attach or an attach? Isn't this going to be the same operation for three states (channel.attach()) Or is it just a wording that states the fact that previously attached channels will be attached again?

  21. SimonWoolf commented on Jan 18, 2023

    @SimonWoolf
    MemberAuthor

    Yeah, that one was very poorly worded. That's why I rewrote it 🙂

    What it was trying to say was that if you're suspended you should start a normal attach (move to the attaching state and send an ATTACH), and if you're in attaching or attached you should send an ATTACH but not otherwise change state.

    In the new spec, this becomes even simpler (The client library should move all channels that were in the @ATTACHING@, @ATTACHED@, or @SUSPENDED@ states to the @ATTACHING@ state, and initiate an @RTL4c@ attach sequence for each.).

    (Again, this is all fixed in protocol-2. Is it really so unfeasable to rebase that branch on main so it can be released without breaking changes?)

  22. ikbalkaya commented on Jan 18, 2023

    @ikbalkaya
    Contributor

    Is it really so unfeasable to rebase that branch on main so it can be released without breaking changes?

    Not really, I actually did that (without adding tests - but tests could also be added easily).
    Commit with other changes added from protocol-2.0 branch (that needs protocol version be 2.0 not 1.3) I remember @paddybyers mentioning this being a big change on standup and was not very keen, but I think given that it actually resolves some existing issues with also using the new protocol it might be worth the change but I cannot know if new issues will emerge as a result.

    My concern was that that was still in draft state even if there are approvals. If other people are ok I can progress with bringing all changes from there.

    I'm also now doing some experiments on whether changes will help some AAT tests pass : ably/ably-asset-tracking-android@99f5b68

  23. paddybyers commented on Jan 18, 2023

    @paddybyers
    Member

    We have two branches: protocol 1.x and protocol 2.0.
    For protocol 1.x we're fixing bugs, but preserving 1.x behaviour.
    For the protocol 2.0 branch, we're getting it to the point that it's stable and ready for release.
    Please let's not confuse those two things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working. It's clear that this does need to be fixed.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions