Commit 16d44c0
fix(runtime): share symbol-keyed metadata by reference across wrappers of one native handle (#5715)
* fix(runtime): #5437 — share native-handle symbol meta across request wrappers (Next.js resolvedPathname)
A native handle (small-id NaN-boxed POINTER, e.g. a node:http IncomingMessage)
carries per-request metadata in the symbol side table keyed by its handle id.
Node shares ONE metadata object by reference across every NodeNextRequest
wrapper that re-news around the same IncomingMessage, so:
- a wrapper read `req[NEXT_REQUEST_META]` resolves to the shared object, and
- a write-back `this._req[SYM] = this[SYM]` is harmless when `this[SYM]` is
the shared object.
In Perry the sharing broke in two ways for a late SSR-bundled wrapper:
1. WIPE: the bundled wrapper reached the write-back with an *undefined*
`this[SYM]`, clobbering the handle's existing metadata to undefined and
losing `resolvedPathname` → Next's `resolvedPathname must be set` invariant.
2. UNSEEDED READ: the bundled wrapper's own `[SYM]` was never set, so the
render's `getRequestMeta` read undefined off it even though its `_req`
handle held the shared meta.
Fix (both gated tightly to native handle-band receivers):
- set_symbol_property: an `undefined` write onto a handle-band receiver that
already holds a non-undefined entry is a no-op (never adds information; the
by-reference object the handle still points at is what Node keeps).
- js_object_get_symbol_property: on a heap-wrapper side-table miss, fall
through to the wrapper's `_req` native handle's symbol meta.
Regression tests cover the share, the wipe-guard, and that a plain heap object
setting a symbol prop to undefined still clears it.
* test(symbol): suppress GC in handle-meta-share tests (parallel cargo-test flake)
The two #5437 handle-meta tests compared a heap `meta` pointer that the
GC-rooted SYMBOL_PROPERTIES side table rewrites on a move while the local
stays stale — deterministic serially (how it was validated), but under
parallel cargo-test a sibling allocation triggers a GC mid-test → spurious
`got != meta`. Wrap each body in gc_suppress()/gc_unsuppress() so the
objects can't move; unsuppress before the assert so a panic can't leak
suppression. The symbol-meta fix itself is unchanged.
* fix(runtime): #5437 — GC-invariant handle-meta tests + CodeRabbit fixes
(A) Make the handle-meta-share tests deterministic under parallel cargo-test
without relying on gc_suppress (which only gates gc_check_trigger, not the
1MB block-alloc trigger). Use an immovable NaN-boxed NUMBER for the metadata
value: numbers are never pointers, so the SYMBOL_PROPERTIES side-table
scanner never rewrites them on a GC move -> got.to_bits() == meta.to_bits()
holds across any collection. wrapper_reads_share_underlying_handle_meta also
forces a full gc() up front to compact the arena so its few allocations
can't trip a mid-test block-alloc GC. The metadata tests now use the exact
Symbol.for("NextInternalRequestMeta") symbol (required by the narrowed
guard below).
(B1) req_handle_symbol_fallback (get.rs): drop the is_small_handle pre-check.
is_valid_obj_ptr already rejects handles and accepts a valid heap object even
at a low address; the pre-check wrongly rejected a real low-address wrapper.
(B2) set_symbol_property (properties.rs): narrow the undefined-write no-op to
ONLY Symbol.for("NextInternalRequestMeta") on a handle-band receiver
(resolved+cached once). Any other handle symbol — including clearing it with
undefined — now stores normally. Added a regression test
(undefined_write_clears_non_metadata_symbol_on_handle).
* test(symbol): handle-meta test ids must be < 0x1000 (Linux is_valid_obj_ptr HEAP_MIN)
The handle-meta tests failed ONLY on x86_64-LINUX CI (pass on arm64 + x86_64
macOS — proven via Rosetta). Root: is_valid_obj_ptr uses HEAP_MIN=0x1000 on
Linux but 0x200_0000_0000 on macOS, so synthetic handle ids 0x4321/0x5678/0x6789
(all >= 0x1000) were classified as valid heap objects on Linux, breaking the
handle-band gate. On macOS they're far below HEAP_MIN so the gate worked. Fix:
ids < 0x1000 (matching real tiny native handles), rejected as non-objects on
every platform. Not a GC race (corrects the prior gc_suppress/number-meta theory).
---------
Co-authored-by: Ralph Küpper <ralph2@skelpo.com>1 parent 393af3c commit 16d44c0
2 files changed
Lines changed: 292 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
64 | 106 | | |
65 | 107 | | |
66 | 108 | | |
| |||
371 | 413 | | |
372 | 414 | | |
373 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
374 | 431 | | |
375 | 432 | | |
376 | 433 | | |
| |||
696 | 753 | | |
697 | 754 | | |
698 | 755 | | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 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 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
219 | 247 | | |
220 | 248 | | |
221 | 249 | | |
| |||
232 | 260 | | |
233 | 261 | | |
234 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
235 | 303 | | |
236 | 304 | | |
237 | 305 | | |
| |||
0 commit comments