Skip to content

Commit

Permalink
Fix cassandra plugin nil pointer dereference issue (uber#4697)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll committed Jan 5, 2022
1 parent d117c3c commit e8fdcd9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions common/persistence/nosql/nosqlplugin/cassandra/workflowUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (db *cdb) executeCreateWorkflowBatchTransaction(
}

if !applied {
requestConditionalRunID := ""
if currentWorkflowRequest.Condition != nil {
requestConditionalRunID = currentWorkflowRequest.Condition.GetCurrentRunID()
}
// There can be two reasons why the query does not get applied. Either the RangeID has changed, or
// the workflow is already started. Check the row info returned by Cassandra to figure out which one it is.
GetFailureReasonLoop:
Expand Down Expand Up @@ -107,7 +111,7 @@ func (db *cdb) executeCreateWorkflowBatchTransaction(

}

if prevRunID := previous["current_run_id"].(gocql.UUID).String(); prevRunID != currentWorkflowRequest.Condition.GetCurrentRunID() {
if prevRunID := previous["current_run_id"].(gocql.UUID).String(); requestConditionalRunID != "" && prevRunID != requestConditionalRunID {
// currentRunID on previous run has been changed, return to caller to handle
msg := fmt.Sprintf("Workflow execution creation condition failed by mismatch runID. WorkflowId: %v, Expected Current RunID: %v, Actual Current RunID: %v",
execution.WorkflowID, currentWorkflowRequest.Condition.GetCurrentRunID(), prevRunID)
Expand Down Expand Up @@ -176,7 +180,10 @@ func (db *cdb) executeUpdateWorkflowBatchTransaction(
requestRunID := currentWorkflowRequest.Row.RunID
requestCondition := PreviousNextEventIDCondition
requestRangeID := shardCondition.RangeID
requestConditionalRunID := *currentWorkflowRequest.Condition.CurrentRunID
requestConditionalRunID := ""
if currentWorkflowRequest.Condition != nil {
requestConditionalRunID = currentWorkflowRequest.Condition.GetCurrentRunID()
}

// There can be three reasons why the query does not get applied: the RangeID has changed, or the next_event_id or current_run_id check failed.
// Check the row info returned by Cassandra to figure out which one it is.
Expand Down Expand Up @@ -210,7 +217,7 @@ func (db *cdb) executeUpdateWorkflowBatchTransaction(
}
} else if rowType == rowTypeExecution && runID == permanentRunID {
// UpdateWorkflowExecution failed because current_run_id is unexpected
if actualCurrRunID = previous["current_run_id"].(gocql.UUID).String(); actualCurrRunID != requestConditionalRunID {
if actualCurrRunID = previous["current_run_id"].(gocql.UUID).String(); requestConditionalRunID != "" && actualCurrRunID != requestConditionalRunID {
// UpdateWorkflowExecution failed because next event ID is unexpected
runIDUnmatch = true
}
Expand Down

0 comments on commit e8fdcd9

Please sign in to comment.