Skip to content

Commit 337a08c

Browse files
authored
PYTHON-2360 Ensure ConnectionCreatedEvents are emitted before ConnectionReadyEvents (#493)
Connections created in the background (for minPoolSize) are authenticated.
1 parent 594b211 commit 337a08c

16 files changed

+148
-83
lines changed

pymongo/pool.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,12 @@ def connect(self, all_credentials=None):
11931193
sock_info.ismaster(all_credentials)
11941194
self.is_writable = sock_info.is_writable
11951195

1196+
try:
1197+
sock_info.check_auth(all_credentials)
1198+
except Exception:
1199+
sock_info.close_socket(ConnectionClosedReason.ERROR)
1200+
raise
1201+
11961202
return sock_info
11971203

11981204
@contextlib.contextmanager

test/cmap/connection-must-have-id.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,32 @@
1212
],
1313
"events": [
1414
{
15-
"type": "ConnectionCheckOutStarted"
15+
"type": "ConnectionCheckOutStarted",
16+
"address": 42
1617
},
1718
{
1819
"type": "ConnectionCreated",
19-
"connectionId": 42
20+
"connectionId": 42,
21+
"address": 42
2022
},
2123
{
2224
"type": "ConnectionCheckedOut",
23-
"connectionId": 42
25+
"connectionId": 42,
26+
"address": 42
2427
},
2528
{
26-
"type": "ConnectionCheckOutStarted"
29+
"type": "ConnectionCheckOutStarted",
30+
"address": 42
2731
},
2832
{
2933
"type": "ConnectionCreated",
30-
"connectionId": 42
34+
"connectionId": 42,
35+
"address": 42
3136
},
3237
{
3338
"type": "ConnectionCheckedOut",
34-
"connectionId": 42
39+
"connectionId": 42,
40+
"address": 42
3541
}
3642
],
3743
"ignore": [

test/cmap/connection-must-order-ids.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,32 @@
1212
],
1313
"events": [
1414
{
15-
"type": "ConnectionCheckOutStarted"
15+
"type": "ConnectionCheckOutStarted",
16+
"address": 42
1617
},
1718
{
1819
"type": "ConnectionCreated",
19-
"connectionId": 1
20+
"connectionId": 1,
21+
"address": 42
2022
},
2123
{
2224
"type": "ConnectionCheckedOut",
23-
"connectionId": 1
25+
"connectionId": 1,
26+
"address": 42
2427
},
2528
{
26-
"type": "ConnectionCheckOutStarted"
29+
"type": "ConnectionCheckOutStarted",
30+
"address": 42
2731
},
2832
{
2933
"type": "ConnectionCreated",
30-
"connectionId": 2
34+
"connectionId": 2,
35+
"address": 42
3136
},
3237
{
3338
"type": "ConnectionCheckedOut",
34-
"connectionId": 2
39+
"connectionId": 2,
40+
"address": 42
3541
}
3642
],
3743
"ignore": [

test/cmap/pool-checkin-destroy-closed.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818
"events": [
1919
{
2020
"type": "ConnectionCheckedOut",
21-
"connectionId": 1
21+
"connectionId": 1,
22+
"address": 42
2223
},
2324
{
2425
"type": "ConnectionPoolClosed",
2526
"address": 42
2627
},
2728
{
2829
"type": "ConnectionCheckedIn",
29-
"connectionId": 1
30+
"connectionId": 1,
31+
"address": 42
3032
},
3133
{
3234
"type": "ConnectionClosed",
3335
"connectionId": 1,
34-
"reason": "poolClosed"
36+
"reason": "poolClosed",
37+
"address": 42
3538
}
3639
],
3740
"ignore": [

test/cmap/pool-checkin-destroy-stale.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818
"events": [
1919
{
2020
"type": "ConnectionCheckedOut",
21-
"connectionId": 1
21+
"connectionId": 1,
22+
"address": 42
2223
},
2324
{
2425
"type": "ConnectionPoolCleared",
2526
"address": 42
2627
},
2728
{
2829
"type": "ConnectionCheckedIn",
29-
"connectionId": 1
30+
"connectionId": 1,
31+
"address": 42
3032
},
3133
{
3234
"type": "ConnectionClosed",
3335
"connectionId": 1,
34-
"reason": "stale"
36+
"reason": "stale",
37+
"address": 42
3538
}
3639
],
3740
"ignore": [

test/cmap/pool-checkin-make-available.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
"events": [
1919
{
2020
"type": "ConnectionCheckedOut",
21-
"connectionId": 1
21+
"connectionId": 1,
22+
"address": 42
2223
},
2324
{
2425
"type": "ConnectionCheckedIn",
25-
"connectionId": 1
26+
"connectionId": 1,
27+
"address": 42
2628
},
2729
{
2830
"type": "ConnectionCheckedOut",
29-
"connectionId": 1
31+
"connectionId": 1,
32+
"address": 42
3033
}
3134
],
3235
"ignore": [

test/cmap/pool-checkin.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"events": [
1616
{
1717
"type": "ConnectionCheckedIn",
18-
"connectionId": 42
18+
"connectionId": 42,
19+
"address": 42
1920
}
2021
],
2122
"ignore": [

test/cmap/pool-checkout-connection.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@
99
],
1010
"events": [
1111
{
12-
"type": "ConnectionCheckOutStarted"
12+
"type": "ConnectionCheckOutStarted",
13+
"address": 42
14+
},
15+
{
16+
"type": "ConnectionCreated",
17+
"connectionId": 1,
18+
"address": 42
19+
},
20+
{
21+
"type": "ConnectionReady",
22+
"connectionId": 1,
23+
"address": 42
1324
},
1425
{
1526
"type": "ConnectionCheckedOut",
16-
"connectionId": 1
27+
"connectionId": 1,
28+
"address": 42
1729
}
1830
],
1931
"ignore": [
20-
"ConnectionPoolCreated",
21-
"ConnectionCreated",
22-
"ConnectionReady"
32+
"ConnectionPoolCreated"
2333
]
2434
}

test/cmap/pool-checkout-multiple.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@
4343
"events": [
4444
{
4545
"type": "ConnectionCheckedOut",
46-
"connectionId": 42
46+
"connectionId": 42,
47+
"address": 42
4748
},
4849
{
4950
"type": "ConnectionCheckedOut",
50-
"connectionId": 42
51+
"connectionId": 42,
52+
"address": 42
5153
},
5254
{
5355
"type": "ConnectionCheckedOut",
54-
"connectionId": 42
56+
"connectionId": 42,
57+
"address": 42
5558
}
5659
],
5760
"ignore": [

test/cmap/pool-checkout-no-idle.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,24 @@
3030
},
3131
{
3232
"type": "ConnectionCheckedOut",
33-
"connectionId": 1
33+
"connectionId": 1,
34+
"address": 42
3435
},
3536
{
3637
"type": "ConnectionCheckedIn",
37-
"connectionId": 1
38+
"connectionId": 1,
39+
"address": 42
3840
},
3941
{
4042
"type": "ConnectionClosed",
4143
"connectionId": 1,
42-
"reason": "idle"
44+
"reason": "idle",
45+
"address": 42
4346
},
4447
{
4548
"type": "ConnectionCheckedOut",
46-
"connectionId": 2
49+
"connectionId": 2,
50+
"address": 42
4751
}
4852
],
4953
"ignore": [

0 commit comments

Comments
 (0)