Skip to content

Commit 5fe6d92

Browse files
committed
Fixed #7985: Hang in case of error when sweep thread is attaching to database - classic server case: i.e. backported fix for #7917
1 parent 85dc868 commit 5fe6d92

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/common/ThreadStart.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ inline ThreadId getThreadId()
112112
#define USE_FINI_SEM
113113
#endif
114114

115-
template <typename TA>
115+
template <typename A>
116+
class EmptyThreadSyncCleanup
117+
{
118+
public:
119+
static void cleanup(A)
120+
{
121+
}
122+
};
123+
124+
template <typename TA, class Cleanup = EmptyThreadSyncCleanup<TA> >
116125
class ThreadFinishSync
117126
{
118127
public:
@@ -203,6 +212,8 @@ class ThreadFinishSync
203212
threadArg->exceptionHandler(ex, threadRoutine);
204213
}
205214
#endif
215+
216+
Cleanup::cleanup(threadArg);
206217
closing = true;
207218
}
208219
};

src/jrd/tra.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -2696,11 +2696,6 @@ namespace {
26962696
: dbb(d)
26972697
{ }
26982698

2699-
void waitForStartup()
2700-
{
2701-
sem.enter();
2702-
}
2703-
27042699
static void runSweep(SweepParameter* par)
27052700
{
27062701
FbLocalStatus status;
@@ -2709,7 +2704,6 @@ namespace {
27092704
// reference is needed to guarantee that provider exists
27102705
// between semaphore release and attach database
27112706
AutoPlugin<JProvider> prov(JProvider::getInstance());
2712-
par->sem.release();
27132707

27142708
AutoDispose<IXpbBuilder> dpb(UtilInterfacePtr()->getXpbBuilder(&status, IXpbBuilder::DPB, NULL, 0));
27152709
status.check();
@@ -2733,14 +2727,26 @@ namespace {
27332727
ex.stuffException(&st);
27342728
if (st->getErrors()[1] != isc_att_shutdown)
27352729
iscLogException("Automatic sweep error", ex);
2730+
2731+
if (dbb)
2732+
{
2733+
dbb->clearSweepStarting();
2734+
SPTHR_DEBUG(fprintf(stderr, "called clearSweepStarting() dbb=%p par=%p\n", dbb, this));
2735+
dbb = NULL;
2736+
}
2737+
}
2738+
2739+
static void cleanup(SweepParameter* par)
2740+
{
2741+
SPTHR_DEBUG(fprintf(stderr, "Cleanup dbb=%p par=%p\n", par->dbb, par));
2742+
delete par;
27362743
}
27372744

27382745
private:
2739-
Semaphore sem;
27402746
Database* dbb;
27412747
};
27422748

2743-
typedef ThreadFinishSync<SweepParameter*> SweepSync;
2749+
typedef ThreadFinishSync<SweepParameter*, SweepParameter> SweepSync;
27442750
typedef HalfStaticArray<SweepSync*, 16> SweepThreads;
27452751
InitInstance<SweepThreads> sweepThreads;
27462752
GlobalPtr<Mutex> swThrMutex;
@@ -2813,10 +2819,9 @@ static void start_sweeper(thread_db* tdbb)
28132819
}
28142820

28152821
AutoPtr<SweepSync> sweepSync(FB_NEW SweepSync(*getDefaultMemoryPool(), SweepParameter::runSweep));
2816-
SweepParameter swPar(dbb);
2817-
sweepSync->run(&swPar);
2822+
SweepParameter* swPar = FB_NEW SweepParameter(dbb);
2823+
sweepSync->run(swPar);
28182824
started = true;
2819-
swPar.waitForStartup();
28202825
sweepThreads().add(sweepSync.release());
28212826
}
28222827
catch (const Exception&)

0 commit comments

Comments
 (0)