Commit 7f91af5
Add-DbaRegServer - Close the store connection its verification call reopens
Every call leaked one connection: after Create(), the command verifies
the registration with Get-DbaRegServer -SqlInstance
$reggroup.ParentServer. That server object rides the store connection
Get-DbaRegServerGroup had already closed, so SMO silently reconnects
it - and because Connect-DbaInstance then rightly reports it did not
open this connection, nothing ever closes it again. One sleeping
session per call, held until the process exits. Import-DbaRegServer
inherits the leak because it registers through this command.
This is what the first -CheckSleepingConnections full run flagged as
Export-DbaRegServer +33: that test file runs Add-DbaRegServer three
times per test, eleven tests, 33 leaked sessions. Measured in the lab:
five calls grew the session count from 1 to 6; the isolated
Export-DbaRegServer file left 25 sessions behind.
The fix mirrors what Add-DbaRegServerGroup already does after its own
verification call: Disconnect-RegServer after the Get, which walks up
to the store and closes only a connection this module opened. Measured
after the fix: five calls stay at 1 session, and the Export file's
count drops from 25 to 1.
The new regression test counts sleeping dbatools sessions through a
server object opened once (a per-call counting command would open
connections of its own), takes a warm-up call so the pooled connection
exists before the baseline, and asserts three more calls add nothing.
Verified red on the unfixed command (expected 3, got 6) and green on
the fix (9 tests, 0 failed).
(do Add-DbaRegServer, Export-DbaRegServer, Import-DbaRegServer)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 0473789 commit 7f91af5
2 files changed
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
| |||
262 | 266 | | |
263 | 267 | | |
264 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
265 | 273 | | |
266 | 274 | | |
267 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
105 | 147 | | |
0 commit comments