FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

Write-capable client is connected in read-mode and is not available on the quorum's audience

Open sumedhb1995 opened this issue 4 years ago • 10 comments

We are seeing a possible race condition where a client is provided a clientId field and reports the "connected" event but is not available on the quorum. As such, hosts listening for this event search for the quorum value using the current clientId, i.e. runtime.getQuorum().getMember(container.clientId) and get undefined.

Based off of a discussion with @jatgarg , this should only happen if the connected client is in "read" mode. Otherwise, all clients that are moving to connected state should be in "write" mode unless an override is provided. Here, we see a client moving to a connected state but it is still only in "read" mode with no override, and as a result, not in the quorum. It seems like there is a race between switching the mode and assigning the client ID.

A state diagram of when the container moves between different connection states, mode states, and readOnly states would be helpful to our partners.

sumedhb1995 avatar Feb 05 '22 00:02 sumedhb1995

I'm not sure what this bug wants :) Yes, "connected" is raised for read and write clients. I'd say that hosts should not care and should only use Audience. I think that maybe we should not even expose quorum at loader layer (to hosts) - I do not see a good reason why host would need to know about these differences. This has some caveats, like Audience is very hard to use. But there is some work on PUSH side to simplify this (and FRS should follow), which should make it possible to make Audience one stop solution.

Maybe other way to say - we should simplify API not to require large diagrams like the issue asks :)

vladsud avatar Feb 08 '22 18:02 vladsud

This is manifesting in a high-priority product bug, more information for those with internal access here: https://teams.microsoft.com/l/message/19:[email protected]/1643315191678?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&groupId=422665a0-7ad3-4d0d-9171-e8881d0397d9&parentMessageId=1643315191678&teamName=FFX%20(Fluid%20Framework%20and%20Experiences)&channelName=Bugs%20%F0%9F%90%9B&createdTime=1643315191678

KRyan avatar Feb 11 '22 17:02 KRyan

@KRyan, can you please clarify what is the bug? I mention that description above is by design. I can see two possible angles here:

  1. What the bug is - clientID does not show up in Audience. That's true, and while it's how system works, it's likely possible to improve it
  2. Code that uses FF has a bug / wrong expectation, and should not use Quorum

Hard to say which one it is, but having clarify is important here, as otherwise this is not actionable issues.

vladsud avatar Feb 11 '22 17:02 vladsud

Makes sense, and I have not been able to investigate deeply myself. @sumedhb1995 can you confirm which case we are seeing regarding the attribution bug? I'll let Omar and Lyndsy on the Teams thread be on point from the FluidX side for more info needed, thanks!

KRyan avatar Feb 11 '22 18:02 KRyan

Hi @vladsud, here is what we found:

  • current Scriptor code listens to the connected event on the componentRuntime object, and upon connected, the current client id is neither found in quorum nor audience.
  • Then Scriptor code listens to the addMember event on the audience object. The addMember event fires with a different client id, and the current client id never appears in the addMember event.
  • connected event fires again without any disconnected event, the current client id changed to the one has been seen in the previous addMember event.
  • After a few seconds (about 5 seconds or so), addMember event fires again, with a new client id.

This is 100% reproducible in the readout meeting notes.

[2022-02-15T19:09:21.901Z] [MODEL: #1]: current client id d2a88cbd-3b0c-456c-a2a9-1265babe9855, Quorum: , Audience: , client mode: read [2022-02-15T19:09:22.559Z] [MODEL: #1]: adding memeber 69f42594-a3ce-4e27-9bca-dda10a46b6ba, current client id d2a88cbd-3b0c-456c-a2a9-1265babe9855, Quorum: , Audience: 69f42594-a3ce-4e27-9bca-dda10a46b6ba, client mode: write [2022-02-15T19:09:22.844Z] [MODEL: #1]: CONNECTED!!! current client id 69f42594-a3ce-4e27-9bca-dda10a46b6ba [2022-02-15T19:09:28.234Z] [MODEL: #1]: adding memeber 09b85204-a6c4-4749-be1c-1384599a6887, current client id 69f42594-a3ce-4e27-9bca-dda10a46b6ba, Quorum: 69f42594-a3ce-4e27-9bca-dda10a46b6ba, Audience: 69f42594-a3ce-4e27-9bca-dda10a46b6ba, 09b85204-a6c4-4749-be1c-1384599a6887, client mode: write

ZeguangWu avatar Feb 15 '22 19:02 ZeguangWu

@ZeguangWu, thanks for details. Which layer do you refer to? Is this IContainer/Container, IContainerRuntime(Base) or some other layer that raises connected events?

Based on your final state, client 69f42594-a3ce-4e27-9bca-dda10a46b6ba is the current clientID and it's present in both Quorum and Audience. So final state seems to be correct.

So, the only thing that looks wrong in your description is that there is no disconnect event in between two connect events. This should never happen.

I glanced at telemetry, and I definitely see disconnects for prior client:

union Office_Fluid_FluidRuntime_* | where Data_containerId == "3363857d-b26d-40e6-91c9-183ddf1c9a11" | project Event_Sequence, Event_Time, Data_eventName, Data_clientId, Data_reason, Data_connectionMode | order by Event_Sequence asc

vladsud avatar Feb 16 '22 08:02 vladsud

Assigning to Mark to follow up, as well as explore how we can make this system simpler.

vladsud avatar Feb 16 '22 08:02 vladsud

@markfields, @ZeguangWu, the issue as it stands right now is not actionable, IMHO Should it be closed?

vladsud avatar Mar 30 '22 18:03 vladsud

I believe there is still a race condition that when a client is connected, the client may not exist in the audience yet. So it's better to get rid of this race condition which will greatly simplify the host logic.

Right now we have some logic to listen to connected event, check if client exists in the audience, listen to addMember event if not. and we have to unregister the event handler properly. Since it is possible that that reconnection happens before the client is added to the audience, and again upon reconnection the client id may change, and the client may or may not exist in the audience, it gets really complex to handle everything properly.

I think we could either repurpose this to track the race condition request, or we can close this one and create a new one for that. @vladsud

ZeguangWu avatar Mar 30 '22 22:03 ZeguangWu

@ZeguangWu - Sounds like this is a dupe of #7275 then, so closing. Thanks for engaging in this space, looking forward to having it cleaned up.

markfields avatar Apr 11 '22 19:04 markfields