duckdb / duckdb/duckdb-postgres

duckdb enters "restricted mode" due to INTERNAL error

Open
#399 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
372
Forks
105
Avg merge
10h 19m
Merged PRs (30d)
18

Description

### What happens?

We ran into an INTERNAL error that makes duckdb enter "restricted mode" and all subsequent queries fail. We had this issue with the adbc client and duckdb-go. Unfortunately, I am not able to reproduce it. I also don't know which other queries were running at the same time while this happened. But I do have a stack trace, so I wanted to ask if anybody with knowledge of the source code sees the issue.

Yesterday, we started a worker process with a duckdb connection. First, it attached over 50 dbs. Mostly duckdb files in read_only mode, but also some postgres databases in read write mode. According to our logs, the databases were all successfully attached.

Less than a minute after this, we see an error of the form:
```
Binder Error: Referenced column "col1" not found in FROM clause!
Candidate bindings: ...
```

Immediately after that, we get the INTERNAL error message "failed to execute query: INTERNAL Error: Unsupported type for CatalogEntry::GetInfo!". The stack trace points to the postgres extension.

Is it possible that here we cast something to `TableCatalogEntry` which is not of this type? https://github.com/duckdb/duckdb/blob/9612b5bea5a6df924daf5ce696d6992df2483bfe/src/function/table/system/duckdb_tables.cpp#L114

I'm not sure where the stack trace points to inside the postgres extension but could it be the `ClearPostgresCaches` is executed at the same time due to the buggy query with unknown column, invalidating the catalog entry references in `duckdb_tables`? https://github.com/duckdb/duckdb-postgres/blob/b9fce43bc5d36bc6db70844f28b7b146e756eb22/src/postgres_extension.cpp#L43

Or does anybody know what else could cause this?

### To Reproduce

I was not able to reproduce this issue. But I have two cases where this happened.

1. We use duckdb-go, and run the query
```
SELECT DISTINCT table_catalog, table_schema, table_name FROM information_schema.tables WHERE table_catalog = 'base'
LIMIT 100001
```
The error message is:
```
INTERNAL Error: Unsupported type for CatalogEntry::GetInfo!

Stack Trace:

/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x768fdc) [0xfffedc5b8fdc]
/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x7690a8) [0xfffedc5b90a8]
/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x76b51c) [0xfffedc5bb51c]
/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x1b9504) [0xfffedc009504]
/usr/local/bin/worker(duckdb::DuckDBTablesFunction(duckdb::ClientContext&, duckdb::TableFunctionInput&, duckdb::DataChunk&)+0x440) [0x1ad0070]
/usr/local/bin/worker(duckdb::PhysicalTableScan::GetData(duckdb::ExecutionContext&, duckdb::DataChunk&, duckdb::OperatorSourceInput&) const+0x54) [0x200ad74]
/usr/local/bin/worker(duckdb::PipelineExecutor::FetchFromSource(duckdb::DataChunk&)+0x68) [0x14ab3e8]
/usr/local/bin/worker(duckdb::PipelineExecutor::Execute(unsigned long)+0xbc) [0x14b621c]
/usr/local/bin/worker(duckdb::PipelineTask::ExecuteTask(duckdb::TaskExecutionMode)+0x174) [0x14b6654]
/usr/local/bin/worker(duckdb::ExecutorTask::Execute(duckdb::TaskExecutionMode)+0xd0) [0x14ad144]
/usr/local/bin/worker(duckdb::Executor::ExecuteTask(bool)+0x80) [0x14b7650]
/usr/local/bin/worker(duckdb::ClientContext::ExecuteTaskInternal(duckdb::ClientContextLock&, duckdb::BaseQueryResult&, bool)+0x54) [0x1455068]
/usr/local/bin/worker(duckdb::PendingQueryResult::ExecuteInternal(duckdb::ClientContextLock&)+0x38) [0x1455898]
/usr/local/bin/worker(duckdb::PendingQueryResult::Execute()+0x38) [0x1455a78]
/usr/local/bin/worker(duckdb_execute_pending+0x64) [0x13ec3d4]
/usr/local/bin/worker(_cgo_b61eb3d17e42_Cfunc_duckdb_execute_pending+0x24) [0x13d5664]
/usr/local/bin/worker() [0xa992ec]

This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/stable/dev/internal_errors
```

2. A month before, we had a similar error message, but with the adbc client:
```
SELECT c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = 'main' AND c.relkind in ('r', 'p')
```

With error message:
```
INTERNAL Error: Unsupported type for CatalogEntry::GetInfo!

Stack Trace:

/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x768fdc) [0xfffef89b8fdc]
/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x7690a8) [0xfffef89b90a8]
/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x76b51c) [0xfffef89bb51c]
/tmp/.duckdb/extensions/v1.4.3/linux_arm64/postgres_scanner.duckdb_extension(+0x1b9504) [0xfffef8409504]
/usr/local/lib/libduckdb.so(duckdb::DuckDBTablesFunction(duckdb::ClientContext&, duckdb::TableFunctionInput&, duckdb::DataChunk&)+0x440) [0xffff5c2f3000]
/usr/local/lib/libduckdb.so(duckdb::PhysicalTableScan::GetData(duckdb::ExecutionContext&, duckdb::DataChunk&, duckdb::OperatorSourceInput&) const+0x54) [0xffff5cb070f4]
/usr/local/lib/libduckdb.so(duckdb::PipelineExecutor::FetchFromSource(duckdb::DataChunk&)+0x68) [0xffff5ccea608]
/usr/local/lib/libduckdb.so(duckdb::PipelineExecutor::Execute(unsigned long)+0xbc) [0xffff5ccf543c]
/usr/local/lib/libduckdb.so(duckdb::PipelineTask::ExecuteTask(duckdb::TaskExecutionMode)+0x174) [0xffff5ccf5874]
/usr/local/lib/libduckdb.so(duckdb::ExecutorTask::Execute(duckdb::TaskExecutionMode)+0xd0) [0xffff5ccec364]
/usr/local/lib/libduckdb.so(duckdb::Executor::ExecuteTask(bool)+0x80) [0xffff5ccf6870]
/usr/local/lib/libduckdb.so(duckdb::ClientContext::ExecuteTaskInternal(duckdb::ClientContextLock&, duckdb::BaseQueryResult&, bool)+0x54) [0xffff5cca1d78]
/usr/local/lib/libduckdb.so(duckdb::PendingQueryResult::ExecuteInternal(duckdb::ClientContextLock&)+0x38) [0xffff5cca25a8]
/usr/local/lib/libduckdb.so(duckdb::PendingQueryResult::Execute()+0x38) [0xffff5cca2788]
/usr/local/lib/libduckdb.so(duckdb::PreparedStatement::Execute(std::unordered_map, std::allocator >, duckdb::BoundParameterData, duckdb::CaseInsensitiveStringHashFunction, duckdb::CaseInsensitiveStringEquality, std::allocator, std::allocator > const, duckdb::BoundParameterData> > >&, bool)+0xd8) [0xffff5cca3618]
/usr/local/lib/libduckdb.so(duckdb_execute_prepared+0x60) [0xffff5cbad9a4]
/usr/local/lib/libduckdb.so(duckdb_adbc::StatementExecuteQuery(AdbcStatement*, ArrowArrayStream*, long*, AdbcError*)+0x3dc) [0xffff5c43d79c]
/usr/local/bin/worker() [0xd31d74]
/usr/local/bin/worker() [0xd2c374]
/usr/local/bin/worker() [0x48232c]

This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/stable/dev/internal_errors
```

### OS:

debian, ARM

### PostgreSQL Version:

### DuckDB Version:
1.4.3

### DuckDB Client:
duckdb-go

### Full Name:
Gishor Sivanrupan

### Affiliation:
Exaforce

### Have you tried this on the latest `main` branch?
No, I wasn't able to reproduce it.

### Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
No, I wasn't able to reproduce it.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.