ducklake icon indicating copy to clipboard operation
ducklake copied to clipboard

Concurrent ATTACH to existing instance

Open staticlibs opened this issue 1 month ago • 0 comments

What happens?

I was testing this MySQL issue duckdb/duckdb-mysql#89 and stumbled upon the behaviour of concurrent ATTACH IF NOT EXISTS that is not specific to MySQL. The example below is converted from Java, it reliably fails with:

Query unexpectedly failed! (test/sql/attach/attach_concurrent.test:15)!
================================================================================
ATTACH IF NOT EXISTS 'ducklake:duckdb_unittest_tempdir/69406/attach_concurrent.db' AS a_ducklake;
================================================================================
Binder Error: Failed to attach DuckLake MetaData "__ducklake_metadata_a_ducklake" at path + "duckdb_unittest_tempdir/69406/attach_concurrent.db"Unique file handle conflict: Cannot attach "__ducklake_metadata_a_ducklake" - the database file "duckdb_unittest_tempdir/69406/attach_concurrent.db" is already attached by database "__ducklake_metadata_a_ducklake"

As I understand the root cause here is not specific to DuckLake, but I was unable to reproduce it by attaching plain DB files concurrently. DuckLake is likely to be the most probable case how users can get this error (using pretty idiomatic Java code) - so reporting it here.

To Reproduce

# name: test/sql/attach/attach_concurrent.test
# description: test attaching the same instance concurrently
# group: [attach]

require ducklake

statement ok
ATTACH 'ducklake:__TEST_DIR__/attach_concurrent.db' AS a_ducklake (DATA_PATH '__TEST_DIR__/attach_concurrent/')

statement ok
DETACH a_ducklake

concurrentloop i 0 8

statement ok
ATTACH IF NOT EXISTS 'ducklake:__TEST_DIR__/attach_concurrent.db' AS a_ducklake

endloop

OS:

Linux x86_64

DuckDB Version:

5652f26b76

DuckLake Version:

a18e174

DuckDB Client:

unittest

Hardware:

No response

Full Name:

Alex Kasko

Affiliation:

DuckDB Labs

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • [x] Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • [x] Yes, I have

staticlibs avatar Nov 14 '25 00:11 staticlibs