fix: remove busy-wait loop and add missing await in EmbeddedChatApi#1167
Open
AbhiramVSA wants to merge 1 commit intoRocketChat:developfrom
Open
fix: remove busy-wait loop and add missing await in EmbeddedChatApi#1167AbhiramVSA wants to merge 1 commit intoRocketChat:developfrom
AbhiramVSA wants to merge 1 commit intoRocketChat:developfrom
Conversation
Remove synchronous busy-wait mutex (while loop) from handleTypingEvent that is unnecessary in single-threaded JavaScript and risks freezing the browser tab. Add missing await on fetch() in sendAttachment so the try/catch block properly catches network errors. Add missing await on response.json() in getUserStatus, userInfo, and userData for consistent error handling.
Author
|
This addresses #1166 — the changes are scoped to a single file |
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.
Acceptance Criteria fulfillment
while (typingHandlerLock) {}) and unnecessary lock fromhandleTypingEvent— JS is single-threaded, no mutex neededawaitonfetch()insendAttachmentso thetry/catchblock catches network errorsinstead of silently bypassing them
awaitonresponse.json()ingetUserStatus,userInfo, anduserDatafor consistenterror handling matching the rest of the file
Fixes # (issue)
Video/Screenshots
Proof that missing
awaitbypassestry/catch:A minimal script (
proof.js) using realfetch()against an unreachable host demonstrates the bug:=== CURRENT CODE (no await — from EmbeddedChatApi.ts L1068) ===
=== FIXED CODE (with await added) ===
Without
await, thetry/catchinsendAttachmentis completely bypassed — fetch errors becomeunhandled rejections. With
await, errors are caught as intended.Busy-wait loop (before):
Line 366 contained
while (typingHandlerLock) {}with a suppressed ESLint warning (// eslint-disable-next-line no-empty). This synchronous busy-wait is unnecessary in single-threadedJavaScript and risks freezing the browser tab if the lock is ever stuck.
PR Test Details
Note: The PR will be ready for live testing at
https://rocketchat.github.io/EmbeddedChat/pulls/pr-1167 after approval. Contributors are
requested to replace
1167with the actual PR number.Replace Fixes # (issue) with the actual issue number once you've created it
#1166