Skip to content

Commit

Permalink
Fix #7625 - Issue with "ALTER SESSION RESET" and implicit cursor close.
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Jul 1, 2023
1 parent d839d63 commit 8a74600
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/dsql/StmtNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8965,11 +8965,11 @@ void SetTransactionNode::genTableLock(DsqlCompilerScratch* dsqlScratch,
//--------------------


void SessionResetNode::execute(thread_db* tdbb, DsqlRequest* request, jrd_tra** traHandle) const
void SessionResetNode::execute(thread_db* tdbb, DsqlRequest* request, jrd_tra**) const
{
SET_TDBB(tdbb);
Attachment* const attachment = tdbb->getAttachment();
attachment->resetSession(tdbb, traHandle);
const auto attachment = tdbb->getAttachment();
attachment->scheduleResetSession();
}


Expand Down
7 changes: 7 additions & 0 deletions src/jrd/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ static void runDBTriggers(thread_db* tdbb, TriggerAction action)
}
}

void Jrd::Attachment::scheduleResetSession()
{
att_flags |= ATT_reset_scheduled;
}

void Jrd::Attachment::resetSession(thread_db* tdbb, jrd_tra** traHandle)
{
jrd_tra* oldTran = traHandle ? *traHandle : nullptr;
Expand Down Expand Up @@ -578,6 +583,8 @@ void Jrd::Attachment::resetSession(thread_db* tdbb, jrd_tra** traHandle)
// reset GTT's
releaseGTTs(tdbb);

att_flags &= ~ATT_reset_scheduled;

// Run ON CONNECT trigger after reset
if (!(att_flags & ATT_no_db_triggers))
runDBTriggers(tdbb, TRIGGER_CONNECT);
Expand Down
4 changes: 3 additions & 1 deletion src/jrd/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ const ULONG ATT_monitor_init = 0x100000L; // Attachment is registered in monito
const ULONG ATT_repl_reset = 0x200000L; // Replication set has been reset
const ULONG ATT_replicating = 0x400000L; // Replication is active
const ULONG ATT_resetting = 0x800000L; // Session reset is in progress
const ULONG ATT_worker = 0x1000000L; // Worker attachment, managed by the engine
const ULONG ATT_reset_scheduled = 0x1000000L; // Session reset scheduled
const ULONG ATT_worker = 0x2000000L; // Worker attachment, managed by the engine

const ULONG ATT_NO_CLEANUP = (ATT_no_cleanup | ATT_notify_gc);

Expand Down Expand Up @@ -726,6 +727,7 @@ class Attachment : public pool_alloc<type_att>
const Firebird::ByteChunk& chunk);

void releaseGTTs(thread_db* tdbb);
void scheduleResetSession();
void resetSession(thread_db* tdbb, jrd_tra** traHandle);

void signalCancel();
Expand Down
12 changes: 12 additions & 0 deletions src/jrd/jrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ EngineContextHolder::EngineContextHolder(CheckStatusWrapper* status, I* interfac
validateHandle(*this, interfacePtr->getHandle());
}

EngineContextHolder::~EngineContextHolder()
{
thread_db* const tdbb = *this;
const auto attachment = tdbb->getAttachment();

if (attachment && attachment->att_use_count == 1 && (attachment->att_flags & ATT_reset_scheduled))
{
auto transaction = tdbb->getTransaction();
attachment->resetSession(tdbb, &transaction);
}
}

// Used in ProfilerManager.cpp
template EngineContextHolder::EngineContextHolder(
CheckStatusWrapper* status, JAttachment* interfacePtr, const char* from, unsigned lockFlags);
Expand Down
1 change: 1 addition & 0 deletions src/jrd/jrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ namespace Jrd {
template <typename I>
EngineContextHolder(Firebird::CheckStatusWrapper* status, I* interfacePtr, const char* from,
unsigned lockFlags = 0);
~EngineContextHolder();
};

class AstLockHolder : public Firebird::ReadLockGuard
Expand Down

0 comments on commit 8a74600

Please sign in to comment.