From 90efde7aa98db488a1a08356ea2adb52abe1b0c0 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 10 Jul 2024 19:48:51 -0700 Subject: [PATCH] handle rare shell i/o error --- src/ServerShell.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ServerShell.cc b/src/ServerShell.cc index 2e5ac379..d65a3a70 100644 --- a/src/ServerShell.cc +++ b/src/ServerShell.cc @@ -82,7 +82,21 @@ void ServerShell::thread_fn() { for (;;) { fprintf(stdout, "newserv> "); fflush(stdout); - string command = fgets(stdin); + string command; + uint64_t read_start_usecs = now(); + try { + command = fgets(stdin); + } catch (const io_error& e) { + // Cygwin sometimes causes fgets() to fail with errno -1 when the + // terminal window is resized. We ignore these events unless the read + // failed immediately (which probably means it would fail again if we + // retried immediately). + if (now() - read_start_usecs < 1000000 || e.error != -1) { + throw; + } + log_warning("I/O error reading from terminal: %s (%d)", e.what(), e.error); + continue; + } // If command is empty (not even a \n), it's probably EOF if (command.empty()) {