Commit 04b8001
Close remaining ChannelDbConnectionPool parity gaps with WaitHandleDbConnectionPool
Differential testing of the two pool implementations (running the full
Functional/Unit/Manual suites under both, plus a bespoke harness) turned up
four behavioural gaps in ChannelDbConnectionPool that had no test coverage.
1. Emancipated connection reclamation. A SqlConnection that was garbage
collected without ever being closed or disposed left its internal connection
permanently occupying a pool slot. At MaxPoolSize this meant every
subsequent Open timed out forever. GetInternalConnection now sweeps for
emancipated connections before parking on the idle channel, mirroring
WaitHandleDbConnectionPool. The sweep is confined to the slow path since it
is O(MaxPoolSize) and allocates a snapshot.
2. Pool metrics were never emitted. PooledConnections, FreeConnections,
ActiveConnections and the soft/hard connect and disconnect counters all read
zero under this pool. Wired up the same call sites the wait handle pool uses.
3. Count reported reservations rather than connections. Reservations include
connections that are still being opened, which broke the SQL Express user
instance path in SqlConnectionFactory.CreateConnection (a `pool.Count <= 0`
check) with a NullReferenceException. Added
ConnectionPoolSlots.ConnectionCount and pointed Count at it.
4. Async opens always completed asynchronously. The wait handle pool makes a
non-blocking, non-creating attempt at an idle connection before enqueuing a
pending open; this pool did not, so OpenAsync against a warm pool always
took a thread pool hop. Added the same fast path, excluding transactional
requests so they still go through the transacted store and enlist properly.
Test changes:
- Added ConnectionPoolVersionScope, which flips the pool version switch and
clears all pools on both entry and exit. Clearing is required because a pool
binds to its implementation at creation time, so without it pools leak across
tests.
- Parameterized ReclaimEmancipatedOnOpenTest, MaxPoolWaitForConnectionTest,
ConnectionResiliencySPIDTest and MetricsTest.PooledConnectionsCounters_Functional
by pool version. Each was verified to fail before the corresponding fix.
- ChannelDbConnectionPoolTest.StressTestAsync awaited its TaskCompletionSource
unconditionally, which hangs now that TryGetConnection can complete
synchronously.
- Three pool-exhaustion unit tests let their owning SqlConnections go out of
scope, so reclamation could legitimately hand the "should time out" waiter a
connection. They now keep the owners alive.
- TvpTest.TestPacketNumberWraparound passed an async lambda to
Task.Factory.StartNew and so awaited a Task<Task>, never observing the inner
task. Added the missing Unwrap.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent c540496 commit 04b8001
9 files changed
Lines changed: 286 additions & 20 deletions
File tree
- src/Microsoft.Data.SqlClient
- src/Microsoft/Data/SqlClient/ConnectionPool
- tests
- Common
- ManualTests
- SQL
- ConnectionPoolTest
- ConnectivityTests
- ParameterTest
- TracingTests
- UnitTests/ConnectionPool
Lines changed: 124 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | | - | |
| 213 | + | |
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| |||
447 | 448 | | |
448 | 449 | | |
449 | 450 | | |
| 451 | + | |
| 452 | + | |
450 | 453 | | |
451 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
452 | 468 | | |
453 | 469 | | |
454 | 470 | | |
| |||
826 | 842 | | |
827 | 843 | | |
828 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
829 | 869 | | |
830 | 870 | | |
831 | 871 | | |
| |||
1008 | 1048 | | |
1009 | 1049 | | |
1010 | 1050 | | |
| 1051 | + | |
| 1052 | + | |
1011 | 1053 | | |
1012 | 1054 | | |
1013 | 1055 | | |
| |||
1113 | 1155 | | |
1114 | 1156 | | |
1115 | 1157 | | |
1116 | | - | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1117 | 1162 | | |
1118 | 1163 | | |
1119 | 1164 | | |
1120 | 1165 | | |
1121 | 1166 | | |
1122 | 1167 | | |
1123 | 1168 | | |
| 1169 | + | |
1124 | 1170 | | |
1125 | 1171 | | |
1126 | 1172 | | |
| |||
1225 | 1271 | | |
1226 | 1272 | | |
1227 | 1273 | | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
1228 | 1286 | | |
1229 | 1287 | | |
1230 | 1288 | | |
| |||
1255 | 1313 | | |
1256 | 1314 | | |
1257 | 1315 | | |
| 1316 | + | |
1258 | 1317 | | |
1259 | 1318 | | |
1260 | 1319 | | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
1261 | 1383 | | |
1262 | 1384 | | |
1263 | 1385 | | |
| |||
Lines changed: 36 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
88 | 91 | | |
89 | | - | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
93 | 104 | | |
94 | 105 | | |
95 | 106 | | |
| |||
127 | 138 | | |
128 | 139 | | |
129 | 140 | | |
| 141 | + | |
130 | 142 | | |
131 | 143 | | |
132 | 144 | | |
| |||
162 | 174 | | |
163 | 175 | | |
164 | 176 | | |
| 177 | + | |
165 | 178 | | |
166 | 179 | | |
167 | 180 | | |
| |||
190 | 203 | | |
191 | 204 | | |
192 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
193 | 228 | | |
194 | 229 | | |
195 | 230 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| 98 | + | |
96 | 99 | | |
97 | 100 | | |
98 | 101 | | |
| |||
Lines changed: 62 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
0 commit comments