This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new aa2c1c2496 fix(c/driver/postgresql): make connection init/release
thread-safe (#4938)
aa2c1c2496 is described below
commit aa2c1c2496d287e111d70d382e5d9af07568488b
Author: Jeremy Tan <[email protected]>
AuthorDate: Fri Oct 30 13:40:06 2026 +1000
fix(c/driver/postgresql): make connection init/release thread-safe (#4938)
Closes #4753
---
c/driver/postgresql/database.cc | 5 +++--
c/driver/postgresql/database.h | 3 ++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/c/driver/postgresql/database.cc b/c/driver/postgresql/database.cc
index a164473550..b416ee7c94 100644
--- a/c/driver/postgresql/database.cc
+++ b/c/driver/postgresql/database.cc
@@ -120,9 +120,10 @@ AdbcStatusCode PostgresDatabase::Init(struct AdbcError*
error) {
}
AdbcStatusCode PostgresDatabase::Release(struct AdbcError* error) {
- if (open_connections_ != 0) {
+ const int32_t open_connections = open_connections_;
+ if (open_connections != 0) {
InternalAdbcSetError(error, "%s%" PRId32 "%s", "[libpq] Database released
with ",
- open_connections_, " open connections");
+ open_connections, " open connections");
return ADBC_STATUS_INVALID_STATE;
}
return ADBC_STATUS_OK;
diff --git a/c/driver/postgresql/database.h b/c/driver/postgresql/database.h
index a608ef2d3d..5842a08f9c 100644
--- a/c/driver/postgresql/database.h
+++ b/c/driver/postgresql/database.h
@@ -18,6 +18,7 @@
#pragma once
#include <array>
+#include <atomic>
#include <cstdint>
#include <memory>
#include <string>
@@ -69,7 +70,7 @@ class PostgresDatabase {
bool use_copy() const { return use_copy_; }
private:
- int32_t open_connections_;
+ std::atomic<int32_t> open_connections_;
std::string uri_;
std::shared_ptr<PostgresTypeResolver> type_resolver_;
std::array<int, 3> postgres_server_version_{};