Skip to content

Commit

Permalink
Fix mysql-d#154 - autoPurge does not handle cases where the server has
Browse files Browse the repository at this point in the history
terminated the connection. In general resetting the connection now
resets all pending states that are moot.
  • Loading branch information
schveiguy committed Jan 27, 2018
1 parent eb7c7f7 commit e3241b6
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions source/mysql/connection.d
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ package:
if(_socket.connected)
_socket.close();
_open = OpenState.notConnected;
// any pending data is gone. Any statements to release will be released
// on the server automatically.
_headersPending = _rowsPending = _binaryPending = false;
statementsToRelease.clear();
}

/// Called whenever mysql-native needs to send a command to the server
Expand All @@ -484,10 +488,19 @@ package:

isAutoPurging = true;
scope(exit) isAutoPurging = false;
scope(failure) kill();

purgeResult();
statementsToRelease.releaseAll();
try
{
purgeResult();
statementsToRelease.releaseAll();
}
catch(Exception e)
{
// likely the connection was closed, so reset any state.
// Don't treat this as a real error, because everything will be reset when we
// reconnect.
kill();
}
}

/++
Expand Down Expand Up @@ -527,8 +540,17 @@ package:
if(id != 0)
doRelease(conn, id);

ids.length = 0;
assumeSafeAppend(ids);
clear();
}

// clear all statements, and reset for using again.
private void clear()
{
if(ids.length)
{
ids.length = 0;
assumeSafeAppend(ids);
}
}
}
StatementsToRelease!(PreparedImpl.immediateRelease) statementsToRelease;
Expand Down

0 comments on commit e3241b6

Please sign in to comment.