Skip to content

Commit

Permalink
PYTHON-4414 Fix order, add then discard is safer
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneHarvey committed Nov 19, 2024
1 parent d46eeae commit 25ca207
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pymongo/asynchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A

conn = AsyncConnection(sock, self, self.address, conn_id) # type: ignore[arg-type]
async with self.lock:
self.active_contexts.discard(tmp_context)
self.active_contexts.add(conn.cancel_context)
self.active_contexts.discard(tmp_context)
if tmp_context.cancelled:
conn.cancel_context.cancel()
try:
Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,8 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect

conn = Connection(sock, self, self.address, conn_id) # type: ignore[arg-type]
with self.lock:
self.active_contexts.discard(tmp_context)
self.active_contexts.add(conn.cancel_context)
self.active_contexts.discard(tmp_context)
if tmp_context.cancelled:
conn.cancel_context.cancel()
try:
Expand Down

0 comments on commit 25ca207

Please sign in to comment.