Crash when creating two tabs from within a batch script launched in the same terminal window #14110

Open
opened 2026-01-31 04:01:13 +00:00 by claunia · 1 comment
Owner

Originally created by @kaetemi on GitHub (Jun 4, 2021).

Originally assigned to: @zadjii-msft on GitHub.

Windows Terminal version (or Windows build number)

1.8.1444

Other Software

No response

Steps to reproduce

Crash when creating two tabs from within a batch script launched in the same terminal window.

Create the following files.

test1.bat:

wt -w test -d . -p "Command Prompt" test2.bat

test2.bat:

wt -w test -d . -p "Command Prompt" test3.bat
wt -w test -d . -p "Command Prompt" test3.bat

test3.bat:

echo Test
pause

There should be no window named "test" at first.

Double click on test1.bat.

Expected Behavior

A window with two tabs showing the "Test" output.

Actual Behavior

Terminal crashes as it attempts to launch the additional tab.

Originally created by @kaetemi on GitHub (Jun 4, 2021). Originally assigned to: @zadjii-msft on GitHub. ### Windows Terminal version (or Windows build number) 1.8.1444 ### Other Software _No response_ ### Steps to reproduce Crash when creating two tabs from within a batch script launched in the same terminal window. Create the following files. test1.bat: ``` wt -w test -d . -p "Command Prompt" test2.bat ``` test2.bat: ``` wt -w test -d . -p "Command Prompt" test3.bat wt -w test -d . -p "Command Prompt" test3.bat ``` test3.bat: ``` echo Test pause ``` There should be no window named "test" at first. Double click on test1.bat. ### Expected Behavior A window with two tabs showing the "Test" output. ### Actual Behavior Terminal crashes as it attempts to launch the additional tab.
claunia added the Issue-BugNeeds-Tag-FixProduct-TerminalPriority-2Area-Remoting labels 2026-01-31 04:01:14 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jul 7, 2021):

Huh, so what's going on here.

wt.exe is a WINDOWS subsystem application. So when cmd.exe launches that process, it doesn't wait for it to finish to return - it immediately moves on to the next command. So launching test1.bat will spawn a conhost running cmd, and that'll launch wt.exe, then find the end of test1.bat, exit cmd, then conhost will immediately exit.

Now, a first WT is launched, and it runs cmd.exe to process test2.bat. That wt window is named "test". That window now spawns cmd.exe to run test2.bat. Same deal, cmd starts, launches wt.exe, launches wt.exe, then exits. Now here's the tricky part - cmd is faster at running those commands than wt is at starting. So the cmd running in the first WT.exe window exits before either of the other wt.exe's spawn. That results in the first WT.exe exiting immediately, because the child process has exited.

This can be visualized easier by adding a sleep 5 to the end of test2.bat. If you do that, the subsequent tabs will open correctly.

Now we've gotten into a weird edge case - both these subsequent wt.exe's are launching at about the same time. I actually found that it was totally possible for the monarch to assign both these windows the name "test", which is NOT GOOD. That also popped open a post-mortem windbg for me, but that didn't actually end up breaking into anything? I wonder if it was attached to a COM thread that we just ate the exception from and kept going.

I'm gonna re-purpose this issue to tracking down whatever allowed both windows to have the name "test", and preventing that in the future, since this is a great test case.

@ future me: I put these scripts in %~%\bin

@zadjii-msft commented on GitHub (Jul 7, 2021): Huh, so what's going on here. `wt.exe` is a WINDOWS subsystem application. So when `cmd.exe` launches that process, it doesn't wait for it to finish to return - it immediately moves on to the next command. So launching `test1.bat` will spawn a conhost running cmd, and that'll launch wt.exe, then find the end of `test1.bat`, exit `cmd`, then conhost will immediately exit. Now, a first WT is launched, and it runs cmd.exe to process `test2.bat`. That wt window is named "test". That window now spawns cmd.exe to run `test2.bat`. Same deal, `cmd` starts, launches `wt.exe`, launches `wt.exe`, then exits. Now here's the tricky part - cmd is faster at running those commands than `wt` is at starting. So the `cmd` running in the first WT.exe window exits _before_ either of the other `wt.exe`'s spawn. That results in the first WT.exe exiting immediately, because the child process has exited. This can be visualized easier by adding a `sleep 5` to the end of `test2.bat`. If you do that, the subsequent tabs _will_ open correctly. Now we've gotten into a weird edge case - both these subsequent `wt.exe`'s are launching at about the same time. I actually found that it was totally possible for the monarch to assign _both_ these windows the name "test", which is _NOT GOOD_. That also popped open a post-mortem windbg for me, but that didn't actually end up breaking into anything? I wonder if it was attached to a COM thread that we just ate the exception from and kept going. I'm gonna re-purpose this issue to tracking down whatever allowed both windows to have the name "test", and preventing that in the future, since this is a great test case. @ future me: I put these scripts in `%~%\bin`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14110