tursodatabase/turso

Foreign Key CASCADE Cycles Cause Stack Overflow

Open

#5.154 geöffnet am 11. Feb. 2026

Auf GitHub ansehen
 (7 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Rust (1.001 Forks)github user discovery
foreign keysgood first issuepanic

Repository-Metriken

Stars
 (19.103 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Description

Self-referential or circular foreign key CASCADE constraints cause stack overflow.

Reproducer

PRAGMA foreign_keys = ON;

CREATE TABLE T (
    id INTEGER PRIMARY KEY,
    parent_id INTEGER REFERENCES T(id) ON DELETE CASCADE
);
INSERT INTO T VALUES (1, NULL), (2, 1), (3, 2), (4, 3);
DELETE FROM T WHERE id = 1;

Crash Message

thread 'main' has overflowed its stack
fatal runtime error: stack overflow, aborting

Per SQLite documentation: "SQLite limits the depth of recursion of triggers in order to prevent a statement involving recursive triggers from using an unbounded amount of memory." The default MAX_TRIGGER_DEPTH is 1000. Turso has no depth limit.

core/translate/fkeys.rs:1444-1665 - Recursive subprograms without depth tracking.


This issue brought to you by Mikaël and Claude Code.

Contributor Guide