Skip to content

Regression: Segmentation fault with DuckDB 1.1.0 when closing connection with certain values in composite primary keys / foreign keys #85

@lukaseder

Description

@lukaseder

From our integration tests, this seems like a minimal reproducer. Use DuckDB 1.1.0's JDBC driver in Dbeaver, then run this script on an empty database:

CREATE TABLE a (
  a INT NOT NULL,
  CONSTRAINT pk_a PRIMARY KEY (a)
);
CREATE TABLE b (
  b VARCHAR(400) NOT NULL,
  CONSTRAINT pk_b PRIMARY KEY(b)
);
CREATE TABLE c (
  b VARCHAR(400) NOT NULL,
  a INTEGER NOT NULL,
  x INTEGER,
  CONSTRAINT pk_c PRIMARY KEY(b, a),
  CONSTRAINT fk_b FOREIGN KEY (b) REFERENCES b (b),
  CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (a)
);

INSERT INTO a VALUES (1),(2),(3),(4);
INSERT INTO b VALUES ('Orell Füssli'), ('Ex Libris'), ('Buchhandlung im Volkshaus');
INSERT INTO c VALUES ('Ex Libris', 1, 1);
INSERT INTO c VALUES ('Buchhandlung im Volkshaus', 3, 1);

All goes well until you disconnect (JDBC Connection.close() when doing this programmatically, or disconnect with Dbeaver or another database utility), then the JVM segfaults with this:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff936e57cb0, pid=20692, tid=24812
#
# JRE version: OpenJDK Runtime Environment Temurin-21+35 (21.0+35) (build 21+35-LTS)
# Java VM: OpenJDK 64-Bit Server VM Temurin-21+35 (21+35-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C  [libduckdb_java1448999379489329685.so+0x747cb0]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\lukas\jOOQ\3.20\workspace\jOOQ-pro\jOOQ-test-integration\hs_err_pid20692.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Here's a pure JDBC based reproducer:

try (Connection c = DriverManager.getConnection("jdbc:duckdb:segfault");
    Statement s = c.createStatement()
) {
    s.executeUpdate("CREATE TABLE a (a INT NOT NULL, CONSTRAINT pk_a PRIMARY KEY (a))");
    s.executeUpdate("CREATE TABLE b (b VARCHAR(400) NOT NULL, CONSTRAINT pk_b PRIMARY KEY(b))");
    s.executeUpdate("CREATE TABLE c (b VARCHAR(400) NOT NULL, a INTEGER NOT NULL, x INTEGER, CONSTRAINT pk_c PRIMARY KEY(b, a), CONSTRAINT fk_b FOREIGN KEY (b) REFERENCES b (b), CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (a))");
    s.executeUpdate("INSERT INTO a VALUES (1),(2),(3),(4)");
    s.executeUpdate("INSERT INTO b VALUES ('Orell Füssli'), ('Ex Libris'), ('Buchhandlung im Volkshaus')");
    s.executeUpdate("INSERT INTO c VALUES ('Ex Libris', 1, 1)");
    s.executeUpdate("INSERT INTO c VALUES ('Buchhandlung im Volkshaus', 3, 1)");
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions