Skip to content

Commit

Permalink
TEIID-4288 narrowing the synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 21, 2016
1 parent 6687f80 commit c3ca093
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions client/src/main/java/org/teiid/jdbc/StatementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,30 @@ public void addBatch(String sql) throws SQLException {
batchedUpdates.add(sql);
}

public synchronized void cancel() throws SQLException {
public void cancel() throws SQLException {
/* Defect 19848 - Mark the statement cancelled before sending the CANCEL request.
* Otherwise, it's possible get into a race where the server response is quicker
* than the exception in the exception in the conditionalWait(), which results in
* the statement.executeQuery() call throwing the server's exception instead of the
* one generated by the conditionalWait() method.
*/
commandStatus = State.CANCELLED;
cancelRequest();
long request = 0;
synchronized (this) {
commandStatus = State.CANCELLED;
checkStatement();
request = currentRequestID;
if (request == -1) {
return;
}
}
//cancel outside of the lock
try {
this.getDQP().cancelRequest(request);
} catch (TeiidProcessingException e) {
throw TeiidSQLException.create(e);
} catch (TeiidComponentException e) {
throw TeiidSQLException.create(e);
}
}

public void clearWarnings() throws SQLException {
Expand Down Expand Up @@ -969,18 +984,6 @@ protected synchronized void timeoutOccurred() {
}
}

protected void cancelRequest() throws SQLException {
checkStatement();

try {
this.getDQP().cancelRequest(currentRequestID);
} catch (TeiidProcessingException e) {
throw TeiidSQLException.create(e);
} catch (TeiidComponentException e) {
throw TeiidSQLException.create(e);
}
}

public void setPayload(Serializable payload) {
this.payload = payload;
}
Expand Down

0 comments on commit c3ca093

Please sign in to comment.