Skip to content

Commit d6decaa

Browse files
rsomla1silvakid
authored andcommitted
WL#10676: DevAPI: asynchronous execution - part1 - fixes
Stmt_op could hold a reference to a cdk session that was destroyed (after the statement has de-registered itself). Fixed by changing reference to a pointer which is set to null when statement is de-registered from its session.
1 parent ccb46a5 commit d6decaa

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

cdk/include/mysql/cdk/mysqlx/result.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,12 @@ class Stmt_op
404404
using Row_processor::col_count_t;
405405
using Row_processor::row_count_t;
406406

407-
Session& m_session;
407+
/*
408+
This points at statement's session as long as the statement is active and
409+
registered with it.
410+
*/
411+
412+
Session *m_session = nullptr;
408413

409414
/*
410415
If several asynchronous statements have been issued, these pointers
@@ -431,21 +436,30 @@ class Stmt_op
431436
Cursor *m_current_cursor = nullptr;
432437

433438
Stmt_op(Session &s)
434-
: m_session(s)
435439
{
436-
m_session.register_stmt(this);
440+
s.register_stmt(this);
441+
// Note: m_session is set during registration.
442+
assert(m_session);
437443
}
438444

439445
virtual ~Stmt_op()
440446
{
441447
discard();
442448
wait();
443-
m_session.deregister_stmt(this);
449+
if (m_session)
450+
m_session->deregister_stmt(this);
451+
}
452+
453+
Session& get_session()
454+
{
455+
// Note: get_session() should not be called for inactive statement.
456+
assert(m_session);
457+
return *m_session;
444458
}
445459

446460
Protocol& get_protocol()
447461
{
448-
return m_session.m_protocol;
462+
return get_session().m_protocol;
449463
}
450464

451465
// Async_op

cdk/mysqlx/result.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bool Stmt_op::do_cont()
6565

6666
assert(ERROR != m_state);
6767
assert(DONE != m_state || m_op);
68+
assert(m_session);
6869

6970
try {
7071

@@ -125,7 +126,7 @@ bool Stmt_op::do_cont()
125126
will be set to NULL so that we don't enter this branch again.
126127
*/
127128

128-
m_session.deregister_stmt(m_prev_stmt);
129+
m_session->deregister_stmt(m_prev_stmt);
129130
assert(nullptr == m_prev_stmt);
130131
}
131132

@@ -195,6 +196,12 @@ bool Stmt_op::do_cont()
195196

196197
bool Stmt_op::is_completed() const
197198
{
199+
if (!m_session)
200+
{
201+
assert(DONE == m_state || ERROR == m_state);
202+
return true;
203+
}
204+
198205
switch (m_state)
199206
{
200207
case ERROR:

cdk/mysqlx/session.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ POP_SYS_WARNINGS_CDK
3939

4040
#include "stmt.h"
4141

42+
4243
namespace cdk {
4344
namespace mysqlx {
4445

@@ -739,6 +740,9 @@ void Session::close()
739740
void Session::register_stmt(Stmt_op *stmt)
740741
{
741742
assert(stmt);
743+
assert(!stmt->m_session);
744+
745+
stmt->m_session = this;
742746

743747
// Append stmt to the end of the list of active statements.
744748

@@ -756,6 +760,12 @@ void Session::deregister_stmt(Stmt_op *stmt)
756760
{
757761
assert(stmt);
758762

763+
if (!stmt->m_session)
764+
return;
765+
766+
assert(stmt->m_session == this);
767+
stmt->m_session = nullptr;
768+
759769
// Remove stmt from the list of active statements.
760770

761771
if (stmt->m_next_stmt)

0 commit comments

Comments
 (0)