Repository navigation
Commit bc23693
committed
fix(subscriptions): do not release the pooled connection a second time on an abort
knex releases a streamed query's connection twice over: from `ensureConnection`'s
finally when the pg query stream ends, and from its own stream's 'close'. The wrapper
added for #1243 defers destroying that stream until the cursor can close, so a query
that ends inside that window — a small result, which is the common case for a REQ —
has already released its connection when the deferred destroy fires 'close' and
releases it again.
tarn matches a release by resource identity, so the second release frees whatever
lease holds that connection by then: the pool can hand one pg client to two requests.
Measured on the wrapper's own fake of knex 3.2.9's semantics: one release before the
guard, two after a source 'end' inside the poll window, one with the guard. The new
case fails on the previous commit (released 2, expected 1) and passes here.
The destroy now runs only for a query that is still open and whose source has not
ended, so the connection is released by the path that owns it.1 parent f42a762 commit bc23693
2 files changed
Lines changed: 48 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
66 | 85 | | |
67 | 86 | | |
68 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 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 | + | |
164 | 192 | | |
165 | 193 | | |
166 | 194 | | |
| |||
0 commit comments