Skip to content

fix(windows): non-blocking input loop, restore Ctrl+C, drive-root path walk#74

Open
FXschwartz wants to merge 5 commits into
Norbert515:mainfrom
serverpod:fix/windows-input-and-paths
Open

fix(windows): non-blocking input loop, restore Ctrl+C, drive-root path walk#74
FXschwartz wants to merge 5 commits into
Norbert515:mainfrom
serverpod:fix/windows-input-and-paths

Conversation

@FXschwartz
Copy link
Copy Markdown

Fixes three Windows only issues:

1. Win32AnsiStdin._eventLoop blocks the Dart isolate

ReadConsoleInputW was called with no timeout, blocking the OS thread until input arrived. While blocked, no timers, futures, signal handlers, or render frames fire. The await Future.delayed(Duration.zero) at the top of the loop only yields between blocking calls.

Fix: call WaitForSingleObject(handle, 16) first; only call ReadConsoleInputW when the handle is signaled. Caps FFI time at ~16ms.

2. Ctrl+C path inactive on Windows

enableRawMode calls stdin.lineMode = false, which on Windows clears ENABLE_PROCESSED_INPUT. Without that flag, Windows doesn't generate CTRL_C_EVENT, so Dart's ProcessSignal.sigint.watch() doesn't fire.

Fix: re-assert ENABLE_PROCESSED_INPUT in startEventLoop(). With ENABLE_LINE_INPUT still off, only Ctrl+C is intercepted; other Ctrl+letter combos still arrive as key events.

3. getProjectDirectory() doesn't terminate on Windows drive roots

if (newParent == parent) is identity equality on Directory (.parent returns a new instance each call, so this never matches). if (newParent.path == '/') is POSIX-only. From a directory with no pubspec.yaml ancestor on Windows, the walk iterates on C:\ indefinitely. Called synchronously from LogServer._writePortFile(), which is awaited in _runApp before TerminalBinding.initialize(), so runApp itself doesn't progress.

Fix: compare paths (newParent.path == parent.path), and fall back to Directory.current.path instead of throwing.

I also added new unit tests in test/utils/nocterm_paths_test.dart cover getProjectDirectory's three behaviors

Copy link
Copy Markdown

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Improves path discovery behavior and Windows console input handling by making project root detection terminate safely across platforms and keeping the Windows stdin event loop responsive (including Ctrl+C/SIGINT behavior).

Changes:

  • Added unit tests for getProjectDirectory() behavior with/without pubspec.yaml.
  • Updated getProjectDirectory() to terminate by comparing paths (works for Windows drive roots) and return cwd when no ancestor contains pubspec.yaml.
  • Updated Windows stdin backend to re-enable ENABLE_PROCESSED_INPUT and poll input availability with WaitForSingleObject to avoid starving the Dart event loop.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
test/utils/nocterm_paths_test.dart Adds tests validating getProjectDirectory() ancestor walking behavior.
lib/src/utils/nocterm_paths.dart Fixes termination condition when walking to filesystem roots; changes fallback behavior.
lib/src/backend/win32_ansi_stdin.dart Makes Windows stdin loop responsive + preserves Ctrl+C generation by adjusting console mode and using a bounded wait.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/src/utils/nocterm_paths.dart
Comment thread test/utils/nocterm_paths_test.dart Outdated
Comment thread lib/src/backend/win32_ansi_stdin.dart
// starving timers and signal handlers.
final waitResult = _waitForSingleObject(_inputHandle, _pollIntervalMs);
if (!_running) break;
if (waitResult != _waitObject0) continue;
@FXschwartz
Copy link
Copy Markdown
Author

@Norbert515 Sorry for the ping, I'm sure you are busy but when you get a chance could you take a look at this PR? No rush!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive TUI exhibits multiple Windows-specific issues (serverpod create, serverpod start --tui) The TUI is not working on Windows

2 participants