Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Closed
lukaseder opened this issue Sep 17, 2024 · 5 comments

Comments

@lukaseder
Copy link

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)");
}
@lukaseder
Copy link
Author

This is a regression from 1.0.0, where this didn't happen

@lukaseder lukaseder changed the title Segmentation fault with DuckDB 1.1.0 when closing connection with certain values in composite primary keys / foreign keys Regression: Segmentation fault with DuckDB 1.1.0 when closing connection with certain values in composite primary keys / foreign keys Sep 17, 2024
@taniabogatsch
Copy link
Contributor

Hi @lukaseder, thank you for reporting this regression.
I cannot reproduce the segmentation fault on our latest main.
I guess that the issue is a duplicate of duckdb/duckdb#13854, which has been fixed in duckdb/duckdb#13858.

@taniabogatsch
Copy link
Contributor

tania@motorbook duckdb % build/release/duckdb segfault.db
v1.0.1-dev5504 86723c9912
Enter ".help" for usage hints.
D CREATE TABLE a (
    a INT NOT NULL,
    CONSTRAINT pk_a PRIMARY KEY (a)
  );
D CREATE TABLE b (
    b VARCHAR(400) NOT NULL,
    CONSTRAINT pk_b PRIMARY KEY(b)
  );
D 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)
  );
D 
D INSERT INTO a VALUES (1),(2),(3),(4);
D INSERT INTO b VALUES ('Orell Füssli'), ('Ex Libris'), ('Buchhandlung im Volkshaus');
D INSERT INTO c VALUES ('Ex Libris', 1, 1);
D INSERT INTO c VALUES ('Buchhandlung im Volkshaus', 3, 1);
D .q
tania@motorbook duckdb % 

@taniabogatsch
Copy link
Contributor

I can reproduce it with v1.1.0 even without the JDBC driver. Since it no longer reproduces, I'll close this issue as fixed. Please don't hesitate to reopen if I missed something.

tania@motorbook duckdb % duckdb v1duckdb.db
v1.1.0 fa5c2fe15f
Enter ".help" for usage hints.
D CREATE TABLE a (
    a INT NOT NULL,
    CONSTRAINT pk_a PRIMARY KEY (a)
  );
...
D INSERT INTO c VALUES ('Buchhandlung im Volkshaus', 3, 1);
D .q
zsh: segmentation fault  duckdb v1duckdb.db
tania@motorbook duckdb % 

@lukaseder
Copy link
Author

Great, thanks for the feedback!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants