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

fix: race condition when forwarding livechat by splitting subscription removal #33381

Merged
merged 4 commits into from
Sep 27, 2024

Conversation

ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Sep 26, 2024

As noted in CORE-696, when a livechat agent forwards a user to another department or agent, the user's chat can sometimes remain stuck in the sidebar of the old agent. Upon investigation, it was found that the old agent (the one forwarding the user) doesn't receive the expected socket event for the subscription deletion, which is crucial for clearing the user from their sidebar.

This issue was introduced in #32540 with the implementation of the BaseRaw.findOneAndDelete method, which is intended to remove a record from a collection and move it to the corresponding trash collection. However, due to the behavior of the RocketChat server's DB Watcher, between the deletion of the record and its insertion into the trash collection, the MongoDB change stream triggers a notification that initiates the DB Watcher flow. The DB Watcher then receives the subscription's trash ID and attempts to find it in the trash collection. At this point, however, the record hasn’t yet been inserted, resulting in a null response. Consequently, the notification of the subscription removal is lost, leaving the user's chat stuck in the old agent's sidebar.

Proposed changes (including videos or screenshots)

This PR modifies the flow of the findOneAndDelete method to first insert the removed document into the trash collection before deleting it from the original collection. Additionally, a rollback condition has been implemented to revert the removal if the trash insertion fails.

Further comments

Shoutout to @matheusbsilva137 and @sampaiodiego for their help in investigating and identifying the root cause of the problem. Your contributions were invaluable!

Copy link
Contributor

dionisio-bot bot commented Sep 26, 2024

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Sep 26, 2024

🦋 Changeset detected

Latest commit: a0b1672

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/models Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Sep 26, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-09-27 17:45 UTC

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 58.35%. Comparing base (5965a1d) to head (a0b1672).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #33381      +/-   ##
===========================================
- Coverage    58.35%   58.35%   -0.01%     
===========================================
  Files         2692     2692              
  Lines        65264    65265       +1     
  Branches     14729    14730       +1     
===========================================
  Hits         38084    38084              
- Misses       24402    24403       +1     
  Partials      2778     2778              
Flag Coverage Δ
unit 75.32% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ricardogarim ricardogarim requested review from a team September 27, 2024 11:40
@ricardogarim ricardogarim marked this pull request as ready for review September 27, 2024 11:40
.changeset/dry-taxis-cry.md Outdated Show resolved Hide resolved
@sampaiodiego sampaiodiego added this to the 6.14 milestone Sep 27, 2024
@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label Sep 27, 2024
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 27, 2024
@ggazzo ggazzo merged commit 92e366e into develop Sep 27, 2024
51 of 52 checks passed
@ggazzo ggazzo deleted the fix/forward-livechat-room branch September 27, 2024 17:45
@ggazzo
Copy link
Member

ggazzo commented Sep 27, 2024

/patch

Copy link
Contributor

dionisio-bot bot commented Sep 27, 2024

Pull request #33389 added to Project: "Patch 6.12.2"

gabriellsh added a commit that referenced this pull request Sep 30, 2024
…ocket.Chat into feat/airgapped-restrictions

* 'feat/airgapped-restrictions' of github.com:RocketChat/Rocket.Chat: (57 commits)
  fix: Async E2EE key exchange not working on develop (#33378)
  chore: Move Apps-Engine to monorepo (#32951)
  chore(Sidepanel): uses only local channels and discussions (#33387)
  chore: add gazzodown preview (#33279)
  fix: Avoid notifying `watch.settings` on uncaught errors (#33376)
  fix: race condition when forwarding livechat by splitting subscription removal (#33381)
  chore: Single Contact ID: improved typings and removed some duplicated code (#33324)
  ci: remove Jira-GitHub security integration (#33384)
  chore: add ui-composer to storybook (#33383)
  regression: `Sidepanel` sort requires refresh after room update (#33370)
  ci: use node20 for release action (#33343)
  Bump rocket.chat to 6.14.0-develop (#33366)
  chore: replace Meteor._localStorage -> Accounts.storageLocation (#33356)
  Release 6.13.0-rc.1
  fix: Avoid destructuring `connectionData` when value is undefined (#33339)
  feat: Adds new admin feature preview setting management (#33212)
  regression: `Sidepanel` color highlight (#33342)
  chore: move common files to core-services (#33341)
  feat: Adds new admin feature preview setting management (#33212)
  chore: create network broker package (#33338)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants