Skip to content

Commit 25ca207

Browse files
committed
PYTHON-4414 Fix order, add then discard is safer
1 parent d46eeae commit 25ca207

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pymongo/asynchronous/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
12961296

12971297
conn = AsyncConnection(sock, self, self.address, conn_id) # type: ignore[arg-type]
12981298
async with self.lock:
1299-
self.active_contexts.discard(tmp_context)
13001299
self.active_contexts.add(conn.cancel_context)
1300+
self.active_contexts.discard(tmp_context)
13011301
if tmp_context.cancelled:
13021302
conn.cancel_context.cancel()
13031303
try:

pymongo/synchronous/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,8 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
12901290

12911291
conn = Connection(sock, self, self.address, conn_id) # type: ignore[arg-type]
12921292
with self.lock:
1293-
self.active_contexts.discard(tmp_context)
12941293
self.active_contexts.add(conn.cancel_context)
1294+
self.active_contexts.discard(tmp_context)
12951295
if tmp_context.cancelled:
12961296
conn.cancel_context.cancel()
12971297
try:

0 commit comments

Comments
 (0)