Repository navigation
Commit df7c891
authored
Tear down the connection when session setup fails in Connection.open() (#20)
* Tear down the connection when session setup fails in Connection.open()
After the TCP connection is established (createConnection + createClient) and
its 'error'/'close' listeners are registered, if openSession() or
requestStatementId() rejects (bad credentials, timeout, or a non-200 status),
the catch only logged the error and rethrew — leaking the open socket and its
listeners. In the pool this propagates through init() with no close(), so each
failed connect attempt leaks a socket.
Mirror close()'s teardown (removeAllListeners + destroy/end + null the refs +
isConnected=false) in the catch before rethrowing, and add a regression test.
Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
* Reset session ids and guard teardown in Connection.open() error path
Address review feedback on #20: on a failed session setup the open()
catch now (1) clears sessionId/statementId so getSessionId() cannot return
a stale id after openSession succeeds but requestStatementId fails, and
(2) wraps the socket teardown in its own try/catch so a cleanup failure
cannot mask the original error that is rethrown below.
Strengthen the regression tests: assert the original setup error surfaces
rather than a teardown error, and add a case asserting that a failure
after openSession clears the session id.
Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
---------
Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>1 parent c13f1e0 commit df7c891
2 files changed
Lines changed: 88 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
95 | 119 | | |
96 | 120 | | |
97 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
132 | 196 | | |
0 commit comments