Skip to content

Commit 8273627

Browse files
authored
No need to wait for a connection closure (#223)
* No need to wait for a connection closure * CHANGELOG
1 parent 1cb6d15 commit 8273627

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## unreleased
22

33
# [SELECT 1 only if we haven't seen any events](https://github.com/anna-money/asyncpg-listen/pull/222)
4+
# [No need to wait for a connection closure](https://github.com/anna-money/asyncpg-listen/pull/223)
45

56

67
## v0.0.8 (2025-05-25)

asyncpg_listen/listener.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ class NotificationListener:
4646
__slots__ = (
4747
"__connect",
4848
"__reconnect_delay",
49+
"__tasks",
4950
)
5051

5152
def __init__(self, connect: ConnectFunc, reconnect_delay: float = 5) -> None:
5253
self.__reconnect_delay = reconnect_delay
5354
self.__connect = connect
55+
self.__tasks = set()
5456

5557
async def run(
5658
self,
@@ -155,7 +157,9 @@ async def __read_notifications(
155157
await asyncio.sleep(per_attempt_keep_alive_budget - elapsed)
156158
logger.warning("Connection was lost")
157159
finally:
158-
await asyncio.shield(connection.close())
160+
close_task = asyncio.create_task(connection.close())
161+
close_task.add_done_callback(self.__tasks.discard)
162+
self.__tasks.add(close_task)
159163
except Exception:
160164
if failed_connect_attempts < MAX_SILENCED_FAILED_CONNECT_ATTEMPTS:
161165
logger.warning("Connection was lost or not established", exc_info=True)

0 commit comments

Comments
 (0)