microsoft / microsoft/terminal

End of output occasionally missing with `"closeOnExit": "never"`

Open
#18,552 1 comment 0 reactions 0 assignees View on GitHub
Area-Server Issue-Bug Product-Terminal
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

### Windows Terminal version

1.23.10353.0

### Windows build number

10.0.22631.0

### Other Software

Build one of those (as is more convenient):

```csharp
using System;

public static class Program
{
public static void Main()
{
for (var i = 0; i <= 20_000; ++i)
Console.WriteLine($"LINE: {i}");
}
}
```

```cpp
#include

int main(int argc, char* argv[])
{
for (int i = 0; i <= 20000; ++i)
std::cout << "LINE: " << i << std::endl;

return 0;
}
```

```rust
fn main() {
for i in 0..=20_000 {
println!("LINE: {i}");
}
}
```

### Steps to reproduce

- In your default profile settings, set *Advanced* -> *Profile termination behavior* to *"Never close automatically"*
JSON equivalent:
```json
"profiles": {
"defaults": {
"closeOnExit": "never"
```

- Build one of the source codes provided above
- Double-click on the compiled exe file (do *not* run it from a shell)

### Expected Behavior

The output should *always* end with the following lines:

```
LINE: 19995
LINE: 19996
LINE: 19997
LINE: 19998
LINE: 19999
LINE: 20000

[process exited with code 0 (0x00000000)]
You can now close this terminal with Ctrl+D, or press Enter to restart.
```

Restarting the process by pressing Enter any number of times should not change this outcome.

### Actual Behavior

Most of the time, the behavior is as expected: the last line reads `LINE: 20000`.

However, after restarting the execution several times by pressing Enter, you can end up on an incomplete output, such as:

![Image](https://github.com/user-attachments/assets/ecfc617b-86b1-4a26-88bd-fb32e8212ce2)

In the case of the C++ app, I even got the output cut in the middle of a line:

![Image](https://github.com/user-attachments/assets/e153444d-e65c-422e-92fc-31f7210fc796)

Getting this output may require 10 to 20 attempts, so please be patient. 😅

The problem is *not* reproducible when looping from a bat file:

```bat
@echo off
:loop
ConsoleApp.exe
pause
goto loop
```

However, a bat file which just runs the exe will reproduce the problem.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with closeOnExit set to never, launching the executable by double-clicking it and restarting with Enter; compare this with execution through a batch file. Trace the closeOnExit process-exit and output-handling path, then verify that repeated restarts always preserve the complete final line and exit message.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.