This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/arrow-flight-sql-postgresql.git


The following commit(s) were added to refs/heads/main by this push:
     new 0fdf128  Show backtrace on crash with debug build (#162)
0fdf128 is described below

commit 0fdf128df8758fb1400f829729cac46b44fa65d8
Author: Sutou Kouhei <[email protected]>
AuthorDate: Mon Nov 13 13:50:43 2023 +0900

    Show backtrace on crash with debug build (#162)
    
    Closes GH-161
---
 meson.build            |  5 +++++
 src/afs.cc             | 28 +++++++++++++++++++++-------
 test/helper/sandbox.rb |  7 +++++--
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/meson.build b/meson.build
index 266af95..103d51b 100644
--- a/meson.build
+++ b/meson.build
@@ -38,6 +38,10 @@ endif
 pg_config_names += ['pg_config']
 pg_config = find_program(pg_config_names, version: '>= 15')
 
+cpp_args = []
+if get_option('buildtype').startswith('debug')
+  cpp_args += ['-DAFS_DEBUG']
+endif
 arrow_flight_sql = dependency(
   'ArrowFlightSql',
   method: 'cmake',
@@ -77,6 +81,7 @@ endif
 afs = shared_module(
   'arrow_flight_sql',
   'src/afs.cc',
+  cpp_args: cpp_args,
   dependencies: [arrow_flight_sql, postgresql],
   name_prefix: '',
   name_suffix: name_suffix,
diff --git a/src/afs.cc b/src/afs.cc
index 9bf1ad5..8b293fd 100644
--- a/src/afs.cc
+++ b/src/afs.cc
@@ -77,8 +77,8 @@ extern "C"
 #      define AFS_FUNC __func__
 #endif
 
-// #define AFS_DEBUG
-#ifdef AFS_DEBUG
+// #define AFS_VERBOSE
+#ifdef AFS_VERBOSE
 #      define P(...) ereport(DEBUG5, errmsg_internal(__VA_ARGS__))
 #else
 #      define P(...)
@@ -139,6 +139,14 @@ afs_sigusr1(SIGNAL_ARGS)
        errno = errnoSaved;
 }
 
+#ifdef AFS_DEBUG
+void
+afs_sigsegv(SIGNAL_ARGS)
+{
+       ereport(FATAL, errcode(ERRCODE_INTERNAL_ERROR), errmsg("CRASHED!!!"), 
errbacktrace());
+}
+#endif
+
 #ifdef PGRN_HAVE_SHMEM_REQUEST_HOOK
 static shmem_request_hook_type PreviousShmemRequestHook = nullptr;
 #endif
@@ -2291,7 +2299,7 @@ class Proxy : public WorkerProcessor {
 
        arrow::Result<int64_t> update(uint64_t sessionID, const std::string& 
query)
        {
-#ifdef AFS_DEBUG
+#ifdef AFS_VERBOSE
                const char* tag = "update";
 #endif
                auto session = find_session(sessionID);
@@ -2334,7 +2342,7 @@ class Proxy : public WorkerProcessor {
        arrow::Result<arrow::flight::sql::ActionCreatePreparedStatementResult> 
prepare(
                uint64_t sessionID, const std::string& query)
        {
-#ifdef AFS_DEBUG
+#ifdef AFS_VERBOSE
                const char* tag = "prepare";
 #endif
                auto session = find_session(sessionID);
@@ -2374,7 +2382,7 @@ class Proxy : public WorkerProcessor {
 
        arrow::Status close_prepared_statement(uint64_t sessionID, const 
std::string& handle)
        {
-#ifdef AFS_DEBUG
+#ifdef AFS_VERBOSE
                const char* tag = "close prepared statement";
 #endif
                auto session = find_session(sessionID);
@@ -2409,7 +2417,7 @@ class Proxy : public WorkerProcessor {
                                     arrow::flight::FlightMessageReader* reader,
                                     arrow::flight::FlightMetadataWriter* 
writer)
        {
-#ifdef AFS_DEBUG
+#ifdef AFS_VERBOSE
                const char* tag = "set parameters";
 #endif
                auto session = find_session(sessionID);
@@ -2500,7 +2508,7 @@ class Proxy : public WorkerProcessor {
                const std::string& handle,
                arrow::flight::FlightMessageReader* reader)
        {
-#ifdef AFS_DEBUG
+#ifdef AFS_VERBOSE
                const char* tag = "update prepared statement";
 #endif
                auto session = find_session(sessionID);
@@ -3092,6 +3100,9 @@ afs_executor(Datum arg)
        pqsignal(SIGTERM, afs_sigterm);
        pqsignal(SIGHUP, afs_sighup);
        pqsignal(SIGUSR1, afs_sigusr1);
+#ifdef AFS_DEBUG
+       pqsignal(SIGSEGV, afs_sigsegv);
+#endif
        BackgroundWorkerUnblockSignals();
 
        auto executor = new Executor(DatumGetInt64(arg));
@@ -3140,6 +3151,9 @@ afs_server(Datum arg)
        pqsignal(SIGTERM, afs_sigterm);
        pqsignal(SIGHUP, afs_sighup);
        pqsignal(SIGUSR1, afs_sigusr1);
+#ifdef AFS_DEBUG
+       pqsignal(SIGSEGV, afs_sigsegv);
+#endif
        BackgroundWorkerUnblockSignals();
 
        {
diff --git a/test/helper/sandbox.rb b/test/helper/sandbox.rb
index 6bd0623..3459d5f 100644
--- a/test/helper/sandbox.rb
+++ b/test/helper/sandbox.rb
@@ -377,8 +377,11 @@ module Helper
         yield
       ensure
         if @postgresql
-          stop_postgres
-          puts(@postgresql.read_log) unless passed?
+          begin
+            stop_postgres
+          ensure
+            puts(@postgresql.read_log) unless passed?
+          end
         end
       end
     end

Reply via email to