Skip to content

Commit ccb46a5

Browse files
rsomla1silvakid
authored andcommitted
WL#10676: DevAPI: asynchronous execution - part1 - fixes
1. Remove error in Stmt_op logic which did not correctly handle a statement that is being discarded. 2. Invalidate a session if errors were detected during its shut down sequence.
1 parent a35f251 commit ccb46a5

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

cdk/mysqlx/result.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ bool Stmt_op::do_cont()
131131

132132
m_op_mdata = false;
133133

134+
if (m_discard)
135+
{
136+
switch (m_state)
137+
{
138+
case ROWS: m_state = DISCARD; break;
139+
case NEXT: m_state = MDATA; break;
140+
default: break;
141+
}
142+
}
143+
134144
switch (m_state)
135145
{
136146
case OK:
@@ -191,6 +201,9 @@ bool Stmt_op::is_completed() const
191201
return true;
192202
case ROWS:
193203
case NEXT:
204+
if (m_discard)
205+
return false;
206+
FALLTHROUGH;
194207
case DONE:
195208
/*
196209
In one of these states we still continue until do_cont() finishes the

cdk/mysqlx/session.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ Session::~Session()
598598
}
599599
catch (...)
600600
{
601+
// Something went wrong - do not try to use this session again.
602+
m_isvalid = false;
601603
}
602604
}
603605

@@ -712,11 +714,16 @@ void Session::clean_up()
712714
void Session::close()
713715
{
714716
if (is_valid())
715-
{
717+
try {
716718
clean_up();
717719
m_protocol.snd_ConnectionClose().wait();
718720
m_protocol.rcv_Reply(*this).wait();
719721
}
722+
catch (...)
723+
{
724+
m_isvalid = false;
725+
throw;
726+
}
720727
m_isvalid = false;
721728
}
722729

devapi/tests/session-t.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,15 +1386,16 @@ TEST_F(Sess, bugs)
13861386
EXPECT_THROW(mysqlx::Session sess(sess_settings), mysqlx::Error);
13871387
}
13881388

1389+
cout << "empty string as password" << endl;
1390+
13891391
{
1390-
// empty string as password
13911392
SessionSettings sess_settings("localhost_not_found", 13009, "rafal", "");
13921393
}
13931394

13941395

1395-
{
1396-
// Using same Result on different sessions
1396+
cout << "Using same Result on different sessions" << endl;
13971397

1398+
{
13981399
SessionSettings settings(SessionOption::PORT, get_port(),
13991400
SessionOption::USER,get_user(),
14001401
SessionOption::PWD, get_password() ?
@@ -1429,7 +1430,8 @@ TEST_F(Sess, bugs)
14291430
catch(...)
14301431
{}
14311432

1432-
//memory leak when using bad ssl_ca
1433+
cout << "memory leak when using bad ssl_ca" << endl;
1434+
14331435
EXPECT_THROW(mysqlx::Session(SessionOption::SSL_CA, "Bad",
14341436
SessionOption::SSL_MODE, SSLMode::VERIFY_CA,
14351437
SessionOption::PORT, get_port(),
@@ -1440,6 +1442,17 @@ TEST_F(Sess, bugs)
14401442
),
14411443
Error);
14421444

1445+
cout << "Session shut-down with pending multi-result set." << endl;
1446+
1447+
{
1448+
Session sess(this);
1449+
1450+
sess.sql("drop procedure if exists test.test").execute();
1451+
sess.sql("CREATE PROCEDURE test.test() BEGIN select 1; select 2; END")
1452+
.execute();
1453+
1454+
SqlResult res = sess.sql("call test.test()").execute();
1455+
}
14431456
}
14441457

14451458

0 commit comments

Comments
 (0)