Commit 7a850ae
committed
feat(server): cap in-flight relay channels per sandbox and globally
Adds two `ResourceExhausted`-returning guards on `open_relay` to bound the
`pending_relays` map against runaway or abusive callers:
- `MAX_PENDING_RELAYS = 256` — upper bound across all sandboxes. Caps the
memory a caller can pin by calling `open_relay` in a loop while no
supervisor ever claims (or the supervisor is hung).
- `MAX_PENDING_RELAYS_PER_SANDBOX = 32` — per-sandbox ceiling so one noisy
tenant can't consume the entire global budget. Sits above the existing
SSH-tunnel per-sandbox cap (20) so tunnel-specific limits still fire
first for that caller.
Both checks and the `pending_relays` insert happen under a single lock
hold so concurrent callers can't each observe "under the cap" and both
insert past it. Adds a `sandbox_id` field on `PendingRelay` so the
per-sandbox count is a single filter over the map without extra indexes.
Tests:
- Two unit tests in `supervisor_session.rs` — assert the global cap and
the per-sandbox cap both return `ResourceExhausted` with the right
message, and a cap-hit on one sandbox doesn't leak onto others.
- One integration test in `supervisor_relay_integration.rs` — bursts 64
concurrent `open_relay` calls at a single sandbox and asserts exactly
32 succeed, exactly 32 are rejected with the per-sandbox message, and
a different sandbox still accepts new relays.
Reaper behaviour is unchanged; the cap makes the map bounded, so the
existing `HashMap::retain` pass stays cheap under any load.1 parent 482980b commit 7a850ae
2 files changed
Lines changed: 165 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
28 | 38 | | |
29 | 39 | | |
30 | 40 | | |
| |||
56 | 66 | | |
57 | 67 | | |
58 | 68 | | |
| 69 | + | |
59 | 70 | | |
60 | 71 | | |
61 | 72 | | |
| |||
186 | 197 | | |
187 | 198 | | |
188 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
189 | 203 | | |
190 | 204 | | |
191 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
192 | 220 | | |
193 | 221 | | |
194 | 222 | | |
195 | 223 | | |
| 224 | + | |
196 | 225 | | |
197 | 226 | | |
198 | 227 | | |
| |||
731 | 760 | | |
732 | 761 | | |
733 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
734 | 833 | | |
735 | 834 | | |
736 | 835 | | |
| |||
785 | 884 | | |
786 | 885 | | |
787 | 886 | | |
| 887 | + | |
788 | 888 | | |
789 | 889 | | |
790 | 890 | | |
| |||
802 | 902 | | |
803 | 903 | | |
804 | 904 | | |
| 905 | + | |
805 | 906 | | |
806 | 907 | | |
807 | 908 | | |
| |||
829 | 930 | | |
830 | 931 | | |
831 | 932 | | |
| 933 | + | |
832 | 934 | | |
833 | 935 | | |
834 | 936 | | |
| |||
847 | 949 | | |
848 | 950 | | |
849 | 951 | | |
| 952 | + | |
850 | 953 | | |
851 | 954 | | |
852 | 955 | | |
| |||
877 | 980 | | |
878 | 981 | | |
879 | 982 | | |
| 983 | + | |
880 | 984 | | |
881 | 985 | | |
882 | 986 | | |
| |||
899 | 1003 | | |
900 | 1004 | | |
901 | 1005 | | |
| 1006 | + | |
902 | 1007 | | |
903 | 1008 | | |
904 | 1009 | | |
| |||
Lines changed: 60 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
310 | 318 | | |
311 | 319 | | |
312 | 320 | | |
| |||
505 | 513 | | |
506 | 514 | | |
507 | 515 | | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
0 commit comments