From 3d230d4000940f98c0faf73978d17f9f2862cc95 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 26 Jan 2024 00:29:29 +0000 Subject: [PATCH] fix: force a sync exiting the pipeline mode Without it there may be a deadlock and we would be waiting to fetch a result that will never come. Close #685. --- docs/news.rst | 9 +++++++++ psycopg/psycopg/_pipeline.py | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index c5a6a7608..f511a39d3 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -7,6 +7,15 @@ ``psycopg`` release notes ========================= +Future releases +--------------- + +Psycopg 3.1.18 (unreleased) +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fix possible deadlock on pipeline exit (:ticket:`685`). + + Current release --------------- diff --git a/psycopg/psycopg/_pipeline.py b/psycopg/psycopg/_pipeline.py index 7064f6038..6b09c69f0 100644 --- a/psycopg/psycopg/_pipeline.py +++ b/psycopg/psycopg/_pipeline.py @@ -132,8 +132,7 @@ class BasePipeline: self._enqueue_sync() yield from self._communicate_gen() finally: - # No need to force flush since we emitted a sync just before. - yield from self._fetch_gen(flush=False) + yield from self._fetch_gen(flush=True) def _communicate_gen(self) -> PQGen[None]: """Communicate with pipeline to send commands and possibly fetch -- 2.47.2