Repository navigation
fix(windows): avoid blocking cross-thread GetWindowTextLengthW in WindowManager::GetCurrent/GetAll - #116
Merged
Conversation
…dowManager::GetCurrent/GetAll
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.
Fixes libnativeapi/nativeapi#76.
Root Cause
WindowManager::GetCurrent()(FindCurrentWindowCandidates) andWindowManager::GetAll()(EnumWindowsCallback), callingGetWindowTextLengthW(hwnd)on a same-process window owned by a different thread dispatchesWM_GETTEXTLENGTHvia synchronousSendMessageW.MediaPlayer SMTC windowhelper HWND on a worker thread blocked inWaitOnAddress), the main UI thread deadlocks indefinitely.Fix
TryGetWindowTextLength(HWND)which usesGetWindowTextLengthWonly for same-thread windows and falls back to boundedSendMessageTimeoutW(hwnd, WM_GETTEXTLENGTH, 0, 0, SMTO_ABORTIFHUNG | SMTO_NORMAL, 50, &length)for cross-thread windows, skipping unresponsive candidates.FindCurrentWindowCandidates, skip hidden candidates once a visible or hidden candidate has already been found so extra hidden helper windows are not queried unnecessarily.window_manager_get_current_windows_testcreating a blocked worker-thread top-level HWND alongside a main-thread app window and verifyingGetCurrent()andGetAll()return promptly.Verification
ctest -C Release -R window_manager_get_current_windows_teston Windows (0.10s).