Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Server release build segfaults during request rendering #606

Open
pveierland opened this issue Feb 26, 2025 · 0 comments
Open

[Bug]: Server release build segfaults during request rendering #606

pveierland opened this issue Feb 26, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@pveierland
Copy link
Contributor

pveierland commented Feb 26, 2025

Description

The tuono server can segfault during rendering of a second response when built for release.

NB: A system with the PKU CPU feature may be needed to reproduce the segfault.

Expected behaviour

It is expected that the server will not segfault.

How to reproduce

Nix is required for easy reproduction, see: https://nixos.org/download/

  1. Build and run the Tuono server:
git clone --branch feat_nix_base https://github.com/pveierland/tuono.git
cd tuono
nix develop
pnpm install && pnpm build
nix build #tuono
cd examples/tuono-app && ../../result/bin/tuono build && cargo run --release
  1. Run curl http://localhost:3000 multiple times. The segfault should occur on the second request.

Notes

  • The segfault appears to occur in v8::Isolate::new within ssr-rs during the initialization of ProdJs::SSR in tuono.

Fix

Making the following update to ssr-rs removes the segfault:

let platform = v8::new_unprotected_default_platform(0, false).make_shared();

https://github.com/Valerioageno/ssr-rs/blob/main/src/ssr.rs#L52

According to the v8 documentation, this indicates that threading use for V8 may not be set up correctly. I was uncertain whether to file this as a bug in ssr-rs or tuono, but I've filed it here as it can be reproduced from tuono.

https://docs.rs/v8/134.1.0/v8/fn.new_unprotected_default_platform.html

Relevant issue: denoland/rusty_v8#1381

Screenshots

No response

System Info

System:
    OS: Linux 6.6 NixOS 24.05 (Uakari) 24.05 (Uakari)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-1370P
    Memory: 37.89 GB / 62.45 GB
    Container: Yes
    Shell: 5.2.37 - /nix/store/p6k7xp1lsfmbdd731mlglrdj2d66mr82-bash-5.2p37/bin/bash
  Binaries:
    Node: 20.18.1 - /nix/store/wfxq6w9bkp5dcfr8yb6789b0w7128gnb-nodejs-20.18.1/bin/node
    Yarn: 1.22.22 - /nix/store/jcgdksj946l5l42c2y9ks2l4g6n74h3f-yarn-1.22.22/bin/yarn
    npm: 10.8.2 - /nix/store/wfxq6w9bkp5dcfr8yb6789b0w7128gnb-nodejs-20.18.1/bin/npm
    pnpm: 9.14.4 - /nix/store/rzxqj4y899lcr3c2rx92pf457dk6086w-pnpm-9.14.4/bin/pnpm
  npmPackages:
    tuono: link:../../packages/tuono => 0.17.8

System info (Rust)

rustc 1.83.0 (90b35a623 2024-11-26)
cargo 1.83.0 (5ffbef321 2024-10-29)
tuono 0.17.8

Additional context

PKU may be required to reproduce the issue (listed in CPU flags as pku):

❯ lscpu
Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          46 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   20
  On-line CPU(s) list:    0-19
Vendor ID:                GenuineIntel
  Model name:             13th Gen Intel(R) Core(TM) i7-1370P
    CPU family:           6
    Model:                186
    Thread(s) per core:   2
    Core(s) per socket:   14
    Socket(s):            1
    Stepping:             2
    CPU(s) scaling MHz:   17%
    CPU max MHz:          5200.0000
    CPU min MHz:          400.0000
    BogoMIPS:             4377.60
    Flags:                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pd
                          pe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmul
                          qdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsav
                          e avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_a
                          d fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves
                           split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku os
                          pke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization features:
  Virtualization:         VT-x
Caches (sum of all):
  L1d:                    544 KiB (14 instances)
  L1i:                    704 KiB (14 instances)
  L2:                     11.5 MiB (8 instances)
  L3:                     24 MiB (1 instance)
NUMA:
  NUMA node(s):           1
  NUMA node0 CPU(s):      0-19
Vulnerabilities:
  Gather data sampling:   Not affected
  Itlb multihit:          Not affected
  L1tf:                   Not affected
  Mds:                    Not affected
  Meltdown:               Not affected
  Mmio stale data:        Not affected
  Reg file data sampling: Mitigation; Clear Register File
  Retbleed:               Not affected
  Spec rstack overflow:   Not affected
  Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
  Srbds:                  Not affected
  Tsx async abort:        Not affected
@pveierland pveierland added the bug Something isn't working label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant