[llvm] [lit] Explicitly unset timer to free thread stack (PR #188717)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 03:32:41 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/188717

Currently the virtual address space usage of lit fluctuates wildly, with peak usage exceeding 4GB, which results in subsequent thread spawning errors on 32-bit systems.

The cause of this is a circular reference in threading._timer (via the callback), which causes the 8MB thread stack to not be immediately reclaimed when the timer is cancelled.

We can avoid this by explicitly unsetting the timer.

>From b34f926b101c0112791f6380118a4282ea0b42f1 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 26 Mar 2026 11:28:41 +0100
Subject: [PATCH] [lit] Explicitly unset timer to free thread stack

Currently the virtual address space usage of lit fluctuates wildly,
with peak usage exceeding 4GB, which results in subsequent thread
spawning errors on 32-bit systems.

The cause of this is a circular reference in threading._timer (via
the callback), which causes the 8MB thread stack to not be
immediately reclaimed when the timer is cancelled.

We can avoid this by explicitly unsetting the timer.
---
 llvm/utils/lit/lit/TestRunner.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index d856642e3f447..8bd44a8c30707 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -126,6 +126,8 @@ def cancel(self):
         if not self.active():
             return
         self._timer.cancel()
+        # Break reference cycle so that thread stack is freed immediately.
+        self._timer = None
 
     def active(self):
         return self.timeout > 0



More information about the llvm-commits mailing list