[PR #18326] Reduce likelihood of races between stdout and cooked stdin reads #31507

Open
opened 2026-01-31 09:47:43 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/18326

State: closed
Merged: Yes


As explained in the comment on _getViewportCursorPosition, printing
to stdout after initiating a cooked stdin reads is a race condition
between the application and the terminal. But we can significantly
reduce the likelihood of this being obvious with this change.

Related to #18265
Possibly related to #18081

Validation Steps Performed

Execute the following Go code and start typing:

package main

import (
	"fmt"
	"time"
)

func main() {
	go func() {
		time.Sleep(50 * time.Millisecond)
		fmt.Printf("Here is a prompt! >")
	}()

	var text string
	fmt.Scanln(&text)
}

Without this change the prompt will disappear,
and with this change in place, it'll work as expected.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/18326 **State:** closed **Merged:** Yes --- As explained in the comment on `_getViewportCursorPosition`, printing to stdout after initiating a cooked stdin reads is a race condition between the application and the terminal. But we can significantly reduce the likelihood of this being obvious with this change. Related to #18265 Possibly related to #18081 ## Validation Steps Performed Execute the following Go code and start typing: ```go package main import ( "fmt" "time" ) func main() { go func() { time.Sleep(50 * time.Millisecond) fmt.Printf("Here is a prompt! >") }() var text string fmt.Scanln(&text) } ``` Without this change the prompt will disappear, and with this change in place, it'll work as expected. ✅
claunia added the pull-request label 2026-01-31 09:47:43 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31507