Repository navigation
Commit 794d5b8
fix(relay): write the link before the allocation bump
The relink upsert updated the allocation row and then wrote the link row.
enableRecovery takes the same two locks the other way round: its EXISTS
subquery locks the link row FOR UPDATE before its UPDATE locks the
allocation row. A same-key relink concurrent with tunnel registration or
recovery could deadlock, and Postgres would abort one request.
The upsert now writes the link first and bumps the allocation generation
second, in the same transaction. That is the link-then-allocation order
enableRecovery uses. Neither write is visible before commit, so the
listing, get and claim windows stay closed, and the bump still waits on
the allocation row lock a claimed release holds while it deletes the
tunnel.
Co-Authored-By: Claude Opus 5.5 <[email protected]>1 parent fd1fe90 commit 794d5b8
2 files changed
Lines changed: 22 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
107 | | - | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
210 | 212 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | 213 | | |
225 | 214 | | |
226 | 215 | | |
| |||
257 | 246 | | |
258 | 247 | | |
259 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
260 | 262 | | |
261 | 263 | | |
262 | 264 | | |
| |||
0 commit comments