From b2087a7b424074ce1daa4c42b2ce968ad90206d7 Mon Sep 17 00:00:00 2001 From: Chris Ren Date: Sun, 25 Oct 2026 19:06:16 -0500 Subject: [PATCH] macOS: Fix kitty freezing when opening a window while a /dev entry is stuck On macOS, ttyname_r() calls devname_r(), which lstat()s every entry in /dev until one matches. New ptys are appended to /dev, so naming the pty of a new window looks up every older entry, and one stuck entry blocks spawn() on the main thread with the GIL held, freezing kitty. ptsname_r() on the master returns the same name with one ioctl() and a stat() of that single path. Other platforms keep ttyname_r(), which does not walk /dev there in the normal case. Fixes #10741 --- docs/changelog.rst | 3 +++ kitty/child.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2e6a940c4..897183902 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -439,6 +439,9 @@ Detailed list of changes spaces, a duplicate path when dropping items from Apple Mail and a memory leak (:iss:`10708`, :iss:`10581`, :iss:`10628`, :iss:`10673`) +- macOS: Fix kitty freezing when opening a new window while another entry in + :file:`/dev` is stuck (:iss:`10741`) + 0.49.2 [2026-10-01] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/child.c b/kitty/child.c index 3bf39fb01..77b6f89dc 100644 --- a/kitty/child.c +++ b/kitty/child.c @@ -107,7 +107,16 @@ spawn(PyObject *self UNUSED, PyObject *args) { &pass_fds)) return NULL; char name[2048] = {0}; - if (ttyname_r(slave, name, sizeof(name) - 1) != 0) { +#ifdef __APPLE__ + // ttyname_r() on macOS calls lstat() on every entry in /dev until it finds + // the pty, so a single stuck entry can hang it. ptsname_r() gets the name + // from the master with an ioctl() instead. + // See https://github.com/kovidgoyal/kitty/issues/10741 + int ret = ptsname_r(master, name, sizeof(name) - 1); +#else + int ret = ttyname_r(slave, name, sizeof(name) - 1); +#endif + if (ret != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; }