Skip to content

stack overflow risk in on_prepare fast forward recursion #2017

Description

@Sertug17

In src/consensus/role_follower.rs:230, on_prepare uses synchronous
recursion to fast forward through chained prepares:

    return self.on_prepare(prepare.0, prepare.1, prepare.2, prepare.3);

This is acknowledged in the code at line 227 with a FIXME comment.
Sync recursion in Rust uses the real call stack. With enough chained
prepares (e.g. after being offline for many slots), each call adds a
stack frame until the ~2MB stack overflows and the node crashes.

Suggested fix: convert the recursive call to an iterative loop by
wrapping the function body in loop { ... break; } where the fast
forward path reassigns local variables and continues instead of
recursing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions