Repository navigation
fix(api): eliminate typingHandlerLock spinlock and main-thread deadlock - #1412
Open
swarnendusahu10-dotcom wants to merge 1 commit into
Open
swarnendusahu10-dotcom wants to merge 1 commit into
swarnendusahu10-dotcom wants to merge 1 commit into
Conversation
Removes the module-scoped typingHandlerLock variable, the synchronous
while (typingHandlerLock) {} spinlock loop, and the 2000ms setTimeout fallback.
In single-threaded JavaScript runtimes, a synchronous while loop blocks
the call stack indefinitely. Because the event loop cannot cycle while the
main thread spins, the setTimeout macrotask can never execute to clear
the lock. If the lock was ever set or an event arrived re-entrantly, the
browser tab entered an unrecoverable freeze with 100% CPU usage.
JavaScript event handlers are already executed sequentially on the event loop,
making the spinlock both completely redundant and actively dangerous. Also added
defensive validation for typingUser to prevent null/empty entries from polluting
the typing status array.
Fixes RocketChat#1354
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #1354
Fixes a potential main-thread deadlock in
packages/api/src/EmbeddedChatApi.ts.Previously,
handleTypingEventutilized a module-scopedlet typingHandlerLockalong with a synchronouswhile (typingHandlerLock) {}spinlock. Because JavaScript operates on a single-threaded event loop, any unhandled error or asynchronous delay while the lock was held caused thewhileloop to starve the event loop indefinitely, resulting in 100% CPU utilization and freezing the browser tab.Changes
typingHandlerLockand redundantwhile (typingHandlerLock) {}spinlock. Since synchronous array modifications in JavaScript run to completion sequentially, the lock is unnecessary.typingUserexists before updating the internaltypingUserslist.@embeddedchat/api.Test Coverage