Skip to content

The native render path crashes on a small thread when a Vue component's data nests deeply #398

Closed

Description

@JuroOravec

What happens

A component that uses Vue, with data nested a few hundred levels deep, crashes the process when it renders on a thread with a small stack and the native render path is on (the default). For example, 100 nested <div c-for="rowN in rows"> elements, rendered in a thread started after threading.stack_size(512 * 1024), which is the macOS default for threads other than the main one:

  • with the native path on, the process exits with SIGILL and no Python traceback;
  • with CITRY_NATIVE_RENDER=0, the same render succeeds;
  • with a 2 MiB thread, both succeed.

This was measured with a debug build of citry-core on macOS arm64, on the branch for #387, which guards the Vue compiler and the server renderer. A release build has smaller frames, so its crash depth is higher, but it is not measured.

Why

write_value in crates/citry_core_py/src/native_render/leaf_json.rs writes a leaf's Python values as JSON. It calls itself once per nested dict, list or tuple, up to its own limit of 200 levels (MAX_DEPTH). Each level reads Python objects through PyO3, so the stack guard the Rust crates use (stacker) cannot help here. CPython 3.14 and later check the stack pointer against the thread's own stack, and a heap segment is outside it.

Possible fix

  • Make write_value iterative: keep the open containers and their iterators on an explicit stack, so the number of Rust frames stays the same at any depth. The output and the declines (too_deep, cycle, not_plain) stay exactly as they are.
  • Or lower the limit on small threads. Rust already declines past 200 levels and lets Python convert the value. Python's own conversion (_json_plain) now uses a bounded number of frames (fix: write deep data for the browser with a bounded number of frames #391).

Tests

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions