Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54edad2

Browse files
Copilotkrlmlr
andcommitted
Add rapi_connection_valid C++ entry point to avoid deadlock in dbIsValid() calls from progress bar handlers
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
1 parentd35bdab commit54edad2

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

‎R/dbIsValid__duckdb_connection.R‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
#' @inheritParams DBI::dbIsValid
33
#' @usage NULL
44
dbIsValid__duckdb_connection<-function(dbObj,...) {
5-
valid<-FALSE
6-
tryCatch(
7-
{
8-
dbGetQuery(dbObj, SQL("SELECT 1"))
9-
valid<-TRUE
10-
},
11-
error=function(c) {
12-
}
13-
)
14-
valid
5+
# Use fast C++ connection validity check instead of executing SELECT 1
6+
# This avoids deadlock issues when called from progress bar handlers
7+
# that already have ScopedInterruptHandler protection
8+
.Call(rapi_connection_valid,dbObj@conn)
159
}
1610

1711
#' @rdname duckdb_connection-class

‎src/connection.cpp‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,31 @@ static void SetDefaultConfigArguments(ClientContext &context) {
8484
delete conn_wrapper;
8585
}
8686
}
87+
88+
[[cpp11::register]]boolrapi_connection_valid(duckdb::conn_eptr_t conn) {
89+
// Check connection validity without acquiring ClientContext locks
90+
// This avoids the "ScopedInterruptHandler already active" issue when
91+
// called from progress bar handlers or other contexts that already
92+
// have interrupt protection
93+
if (!conn || !conn.get()) {
94+
returnfalse;
95+
}
96+
97+
auto conn_wrapper = conn.get();
98+
if (!conn_wrapper) {
99+
returnfalse;
100+
}
101+
102+
// Check if the connection object exists
103+
if (!conn_wrapper->conn) {
104+
returnfalse;
105+
}
106+
107+
// Check if the database wrapper is still valid
108+
if (!conn_wrapper->db || !conn_wrapper->db->db) {
109+
returnfalse;
110+
}
111+
112+
// All checks passed - connection appears valid
113+
returntrue;
114+
}

‎src/include/rapi.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ duckdb::conn_eptr_t rapi_connect(duckdb::db_eptr_t);
219219

220220
voidrapi_disconnect(duckdb::conn_eptr_t);
221221

222+
boolrapi_connection_valid(duckdb::conn_eptr_t);
223+
222224
cpp11::listrapi_prepare(duckdb::conn_eptr_t, std::string);
223225

224226
cpp11::listrapi_bind(duckdb::stmt_eptr_t, SEXP paramsexp, duckdb::ConvertOpts);

‎src/include/signal.hpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
namespaceduckdb {
1111

12+
//! ScopedInterruptHandler serves a dual purpose:
13+
//! 1. Install interrupt handler: Installs a signal handler to catch SIGINT
14+
//! and properly interrupt DuckDB operations by calling ClientContext::Interrupt()
15+
//! 2. Avoid reentrant calls: Ensures only one ScopedInterruptHandler is active at a time,
16+
//! preventing deadlocks when operations are called from within signal handlers
17+
//! (such as progress bar callbacks). Throws "ScopedInterruptHandler already active"
18+
//! if instantiated while another instance is already active.
1219
classScopedInterruptHandler {
1320
private:
1421
shared_ptr<ClientContext> context;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp