Skip to content

Commit

Permalink
fix: use CancelIoEx to cancel Windows conInputReader across threads (#…
Browse files Browse the repository at this point in the history
…1305)

The Windows conInputReader uses `windows.CancelIo` to close the read
loop's input handle. Windows `CancelIo` docs indicate that call is only
appropriate for I/O operations on the same thread as the `CancelIo`
call. Since the read loop is in its own goroutine, it's likely to be on
another thread from the bubbletea Program.

This change adds a call to Windows `CancelIoEx`, which will cancel I/O
operations across threads.

Fixes #1167
  • Loading branch information
awoodbeck authored Feb 4, 2025
1 parent 22ba68a commit c8d6005
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion inputreader_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newInputReader(r io.Reader) (cancelreader.CancelReader, error) {
func (r *conInputReader) Cancel() bool {
r.setCanceled()

return windows.CancelIo(r.conin) == nil
return windows.CancelIoEx(r.conin, nil) == nil || windows.CancelIo(r.conin) == nil
}

// Close implements cancelreader.CancelReader.
Expand Down

0 comments on commit c8d6005

Please sign in to comment.