From: JulienPalard (@JulienPalard) <noreply+JulienPalard@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: Re: [psycopg/psycopg] issue #1427: Hang in futex, linked to garbage collection
Date: Mon, 28 Sep 2026 11:39:42 +0000
Message-ID: <gh-psycopg-psycopg-1427-c5869112525@github.com> (raw)
In-Reply-To: <gh-psycopg-psycopg-1427@github.com>
References: <gh-psycopg-psycopg-1427@github.com>
As far as I understand now: during a psycopg.cursor.execute, while the lock is held, a GC triggers, leading to a call to _server_cursor.close, which tries to take the lock but can't. The GC pass never ends, deadlocking the thread.
Can easily be shown by using:
```
import gc
gc.set_debug(gc.DEBUG_STATS)`
```
showing this at the end of a locked process:
```
gc: collecting generation 0...
gc: objects in each generation: 2144 8269 343198
gc: objects in permanent generation: 0
```
A normal GC run ends with `gc: done, 35 unreachable, 0 uncollectable, 0.0010s elapsed`.