Skip to content

fix: guard _resize against disposed _resizeDebouncer (fixes #317787)#317791

Merged
vs-code-engineering[bot] merged 1 commit into
mainfrom
fix/terminal-resize-disposed-317787-e26d5b2d5c562f86
May 21, 2026
Merged

fix: guard _resize against disposed _resizeDebouncer (fixes #317787)#317791
vs-code-engineering[bot] merged 1 commit into
mainfrom
fix/terminal-resize-disposed-317787-e26d5b2d5c562f86

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🔧 Error Fix

Summary

Error: Cannot read properties of undefined (reading 'resize') in terminalInstance._resize

Root cause: Commit dff2ee20 ("fix: dispose resize debouncer before process manager to prevent race", part of #315284) moved _resizeDebouncer disposal earlier in the terminal teardown sequence — before _processManager.dispose(). This prevents resize callbacks from reaching a nulled ptyProcessReady, but introduces a new race: configuration change events (e.g. from terminalSuggestConfiguration registration) can fire during the dispose sequence and trigger setVisible_resize, which crashes because _resizeDebouncer is already undefined.

Impact: 195 affected users across 4 coalesced buckets on all platforms.

Fixes #317787
Recommended reviewer: @Tyriar

Culprit Commit

Field Value
Commit dff2ee20
Title fix: guard setDimensions against disposed ptyProcessReady (fixes #315282) (#315284)
Author @vs-code-engineering[bot] / @bryanchen-d (co-author)
Date 2026-05-19
Regression window 553c727...e9f40e5 (May 18 16:12 → May 18 23:45)

Code Flow

sequenceDiagram
    participant User
    participant TI as TerminalInstance
    participant RD as ResizeDebouncer
    participant CS as ConfigService
    participant TSC as TerminalSuggestConfig

    User->>TI: dispose()
    TI->>RD: dispose()
    Note over TI: _resizeDebouncer = undefined
    TI->>CS: (dispose continues...)
    TSC->>CS: updateConfigurations()
    CS->>TI: onDidChangeConfiguration fires
    TI->>TI: setVisible(_isVisible)
    TI->>TI: _resize()
    Note over TI: this._resizeDebouncer!.resize() 💥 undefined
Loading

Affected Files

File Role
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Crash site — _resize uses _resizeDebouncer! after it's been disposed
src/vs/workbench/contrib/terminalContrib/suggest/common/terminalSuggestConfiguration.ts Triggers configuration registration during startup that fires config change events

Repro Steps

  1. Open a terminal in VS Code
  2. Close/dispose the terminal while a terminal suggest configuration is being registered
  3. The config change event fires setVisible_resize after _resizeDebouncer is already disposed
  4. TypeError thrown at _resizeDebouncer!.resize()

How the Fix Works

Chosen approach (src/vs/workbench/contrib/terminal/browser/terminalInstance.ts):

Added !this._resizeDebouncer to the existing early-return guard at the top of _resize(). When _resizeDebouncer is undefined (meaning the instance is mid-disposal), the method returns immediately before any resize logic executes. This is a guard clause upstream of the crash site — it prevents the error from being produced rather than catching it after the fact. Also replaced the ! non-null assertion on the .resize() call with optional chaining (?.) as a safety net against any other path that could reach this line post-disposal.

This follows the principle of fixing at the data producer (the disposal sequence that nulls _resizeDebouncer) by guarding callers that can still fire during that window, rather than wrapping the crash in try/catch.

Recommended Owner

Owner Reason
@Tyriar Primary owner of terminal infrastructure; authored disposal ordering logic

Generated by errors-fix · ● 43.3M ·

When a terminal is being disposed, _resizeDebouncer is set to undefined
before the dispose sequence completes. If a configuration change event
fires during disposal (e.g. from terminalSuggestConfiguration
registration), setVisible -> _resize is called and crashes trying to
call .resize() on undefined.

Add _resizeDebouncer to the early-return check at the top of _resize
and replace the non-null assertion with optional chaining as a safety
net.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 16:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot requested a review from Copilot May 21, 2026 16:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot requested a review from Copilot May 21, 2026 16:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot marked this pull request as ready for review May 21, 2026 16:18
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 21, 2026 16:18
@vs-code-engineering vs-code-engineering Bot merged commit d1a4f1b into main May 21, 2026
25 checks passed
@vs-code-engineering vs-code-engineering Bot deleted the fix/terminal-resize-disposed-317787-e26d5b2d5c562f86 branch May 21, 2026 17:21
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants