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": [

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
},
2727
{
2828
"type": "ConnectionCheckedOut",
29-
"connectionId": 1
29+
"connectionId": 1,
30+
"address": 42
3031
},
3132
{
3233
"type": "ConnectionCheckedIn",
33-
"connectionId": 1
34+
"connectionId": 1,
35+
"address": 42
3436
},
3537
{
3638
"type": "ConnectionPoolCleared",
@@ -39,11 +41,13 @@
3941
{
4042
"type": "ConnectionClosed",
4143
"connectionId": 1,
42-
"reason": "stale"
44+
"reason": "stale",
45+
"address": 42
4346
},
4447
{
4548
"type": "ConnectionCheckedOut",
46-
"connectionId": 2
49+
"connectionId": 2,
50+
"address": 42
4751
}
4852
],
4953
"ignore": [

test/cmap/pool-close-destroy-conns.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
"events": [
2525
{
2626
"type": "ConnectionCheckedIn",
27-
"connectionId": 2
27+
"connectionId": 2,
28+
"address": 42
2829
},
2930
{
3031
"type": "ConnectionClosed",
3132
"connectionId": 2,
32-
"reason": "poolClosed"
33+
"reason": "poolClosed",
34+
"address": 42
3335
},
3436
{
3537
"type": "ConnectionPoolClosed",

test/cmap/pool-create-max-size.json

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,59 +53,74 @@
5353
"options": 42
5454
},
5555
{
56-
"type": "ConnectionCheckOutStarted"
56+
"type": "ConnectionCheckOutStarted",
57+
"address": 42
5758
},
5859
{
5960
"type": "ConnectionCreated",
60-
"connectionId": 42
61+
"connectionId": 42,
62+
"address": 42
6163
},
6264
{
6365
"type": "ConnectionCheckedOut",
64-
"connectionId": 42
66+
"connectionId": 42,
67+
"address": 42
6568
},
6669
{
67-
"type": "ConnectionCheckOutStarted"
70+
"type": "ConnectionCheckOutStarted",
71+
"address": 42
6872
},
6973
{
7074
"type": "ConnectionCreated",
71-
"connectionId": 42
75+
"connectionId": 42,
76+
"address": 42
7277
},
7378
{
7479
"type": "ConnectionCheckedOut",
75-
"connectionId": 42
80+
"connectionId": 42,
81+
"address": 42
7682
},
7783
{
78-
"type": "ConnectionCheckOutStarted"
84+
"type": "ConnectionCheckOutStarted",
85+
"address": 42
7986
},
8087
{
8188
"type": "ConnectionCreated",
82-
"connectionId": 42
89+
"connectionId": 42,
90+
"address": 42
8391
},
8492
{
8593
"type": "ConnectionCheckedOut",
86-
"connectionId": 42
94+
"connectionId": 42,
95+
"address": 42
8796
},
8897
{
8998
"type": "ConnectionCheckedIn",
90-
"connectionId": 42
99+
"connectionId": 42,
100+
"address": 42
91101
},
92102
{
93-
"type": "ConnectionCheckOutStarted"
103+
"type": "ConnectionCheckOutStarted",
104+
"address": 42
94105
},
95106
{
96107
"type": "ConnectionCheckedOut",
97-
"connectionId": 42
108+
"connectionId": 42,
109+
"address": 42
98110
},
99111
{
100-
"type": "ConnectionCheckOutStarted"
112+
"type": "ConnectionCheckOutStarted",
113+
"address": 42
101114
},
102115
{
103116
"type": "ConnectionCheckedIn",
104-
"connectionId": 42
117+
"connectionId": 42,
118+
"address": 42
105119
},
106120
{
107121
"type": "ConnectionCheckedOut",
108-
"connectionId": 42
122+
"connectionId": 42,
123+
"address": 42
109124
}
110125
],
111126
"ignore": [

0 commit comments

Comments
 (0)