From 1d1e3a5170737dc2101b4f74010ae46bbef6acf5 Mon Sep 17 00:00:00 2001 From: AlexPeshkoff Date: Fri, 5 Jan 2024 19:37:39 +0300 Subject: [PATCH] Postfix for #7917: Hang in a case of error when sweep thread is attaching to database; fixed CS case. --- src/common/ThreadStart.h | 5 ++++- src/jrd/tra.cpp | 27 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/common/ThreadStart.h b/src/common/ThreadStart.h index cbedab06d25..7c5ef669533 100644 --- a/src/common/ThreadStart.h +++ b/src/common/ThreadStart.h @@ -112,7 +112,7 @@ inline ThreadId getThreadId() #define USE_FINI_SEM #endif -template +template class ThreadFinishSync { public: @@ -203,6 +203,9 @@ class ThreadFinishSync threadArg->exceptionHandler(ex, threadRoutine); } #endif + + if (cleanup) + cleanup(threadArg); closing = true; } }; diff --git a/src/jrd/tra.cpp b/src/jrd/tra.cpp index 11a04cc91e0..591f9f22bea 100644 --- a/src/jrd/tra.cpp +++ b/src/jrd/tra.cpp @@ -2718,11 +2718,6 @@ namespace { : dbb(d) { } - void waitForStartup() - { - sem.enter(); - } - static void runSweep(SweepParameter* par) { FbLocalStatus status; @@ -2745,7 +2740,6 @@ namespace { prov->setDbCryptCallback(&status, cryptCallback); status.check(); } - par->sem.release(); AutoDispose dpb(UtilInterfacePtr()->getXpbBuilder(&status, IXpbBuilder::DPB, nullptr, 0)); status.check(); @@ -2769,14 +2763,26 @@ namespace { ex.stuffException(&st); if (st->getErrors()[1] != isc_att_shutdown) iscLogException("Automatic sweep error", ex); + + if (dbb) + { + dbb->clearSweepStarting(); + SPTHR_DEBUG(fprintf(stderr, "called clearSweepStarting() dbb=%p par=%p\n", dbb, this)); + dbb = nullptr; + } + } + + static void cleanup(SweepParameter* par) + { + SPTHR_DEBUG(fprintf(stderr, "Cleanup dbb=%p par=%p\n", par->dbb, par)); + delete par; } private: - Semaphore sem; Database* dbb; }; - typedef ThreadFinishSync SweepSync; + typedef ThreadFinishSync SweepSync; InitInstance > sweepThreads; GlobalPtr swThrMutex; bool sweepDown = false; @@ -2848,10 +2854,9 @@ static void start_sweeper(thread_db* tdbb) } AutoPtr sweepSync(FB_NEW SweepSync(*getDefaultMemoryPool(), SweepParameter::runSweep)); - SweepParameter swPar(dbb); - sweepSync->run(&swPar); + SweepParameter* swPar = FB_NEW_POOL(*dbb->dbb_permanent) SweepParameter(dbb); + sweepSync->run(swPar); started = true; - swPar.waitForStartup(); sweepThreads().add(sweepSync.release()); } catch (const Exception&)