Fix race condition in terminal event handling by filtering func host events#4888
Fix race condition in terminal event handling by filtering func host events#4888Copilot wants to merge 2 commits intonat/debuggerViewfrom
Conversation
|
@copilot Here's the feedback from the comment: The terminal shell execution event listener is registered before func host task starts and stores the latest event in a global variable. This creates a race condition: if multiple terminals are opened or if a non-func terminal is opened just before the func task starts, latestTerminalShellExecutionEvent could point to the wrong terminal. Consider matching terminals more precisely by correlating the task execution with the terminal, or by checking if the terminal's command matches the func host start pattern when consuming the stream. |
…events Co-authored-by: nturinski <[email protected]>
Fixed the race condition by filtering terminal events to only store those matching the func host start pattern. The Commit: d076846 |
This PR addresses feedback from comment #2692434759 on PR #4883 regarding a race condition in terminal event handling in the function host debugger view.
Problem
The original implementation stored ALL terminal shell execution events in a global variable (
latestTerminalShellExecutionEvent). This created a race condition where if multiple terminals were opened or if a non-func terminal was opened just before the func task starts, the wrong terminal's stream could be captured.Solution
Modified the
onDidStartTerminalShellExecutionevent listener to filter terminal events using the existingisFuncShellEventfunction. Now only terminal events that match the func host start pattern (/(func(?:\.exe)?)\s+host\s+start/i) are stored, preventing non-func terminals from being incorrectly captured.Changes Made
registerFuncHostTaskEvents()to only store terminal events for func host start commandsisFuncShellEventhelper function for consistencyTesting
The changes are minimal and surgical, leveraging existing helper functions to eliminate the race condition while maintaining backward compatibility.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.