Commit 8e5120d
committed
fix(tail): reap closed follow-sessions instead of leaking them
The module-level sessions Map dropped an entry only on an explicit
ssh_tail_stop. A follow-start whose stream closed (remote ended,
connection dropped) but was never explicitly stopped left its state
in the Map for the server's lifetime. The 1 MB ring buffer bounds
per-session memory, but closed sessions were never reaped.
Track readOffset (highest delivered offset) and closedAt per session.
reapClosedSessions() drops a closed session once its buffer is fully
read, or once it has been closed past a grace period even if unread
(the stream is dead). It runs on every follow-start and follow-read.
handleSshTailRead's opening sweep excludes the session it is about to
serve so the caller still gets one final closed:true read; that
session is then reaped at the end of the call.
Tests: a closed + fully-read session is reaped on the next read with
no explicit stop (fails without the fix), a closed session past the
grace window is reaped even if never read, and an open session
survives any sweep.1 parent 55e41fa commit 8e5120d
2 files changed
Lines changed: 124 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
40 | 65 | | |
41 | 66 | | |
42 | 67 | | |
43 | 68 | | |
44 | 69 | | |
45 | 70 | | |
46 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
47 | 77 | | |
48 | 78 | | |
49 | 79 | | |
| |||
151 | 181 | | |
152 | 182 | | |
153 | 183 | | |
| 184 | + | |
154 | 185 | | |
| 186 | + | |
155 | 187 | | |
156 | 188 | | |
157 | 189 | | |
| |||
164 | 196 | | |
165 | 197 | | |
166 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
167 | 204 | | |
168 | 205 | | |
169 | | - | |
170 | | - | |
| 206 | + | |
| 207 | + | |
171 | 208 | | |
| 209 | + | |
172 | 210 | | |
173 | 211 | | |
174 | 212 | | |
| |||
198 | 236 | | |
199 | 237 | | |
200 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
201 | 243 | | |
202 | 244 | | |
203 | 245 | | |
| |||
241 | 283 | | |
242 | 284 | | |
243 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
244 | 292 | | |
245 | 293 | | |
246 | 294 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
372 | 374 | | |
373 | 375 | | |
374 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
375 | 449 | | |
376 | 450 | | |
377 | 451 | | |
| |||
0 commit comments