Bugfix: shard context should get default encoding before acquire shard lock, or otherwise, deadlock will happen
@@ -416,15 +416,15 @@ func (s *shardContextImpl) getDefaultEncoding(domainID string) (common.EncodingT
}
func (s *shardContextImpl) UpdateWorkflowExecution(request *persistence.UpdateWorkflowExecutionRequest) (*persistence.UpdateWorkflowExecutionResponse, error) {
- s.Lock()
- defer s.Unlock()
-
encoding, err := s.getDefaultEncoding(request.ExecutionInfo.DomainID)
if err != nil {
return nil, err
}
request.Encoding = encoding
+ s.Lock()
+ defer s.Unlock()
+
transferMaxReadLevel := int64(0)
// assign IDs for the transfer tasks
// Must be done under the shard lock to ensure transfer tasks are written to persistence in increasing
@@ -520,15 +520,15 @@ Update_Loop:
}
func (s *shardContextImpl) ResetMutableState(request *persistence.ResetMutableStateRequest) error {
- s.Lock()
- defer s.Unlock()
-
encoding, err := s.getDefaultEncoding(request.ExecutionInfo.DomainID)
if err != nil {
return err
}
request.Encoding = encoding
+ s.Lock()
+ defer s.Unlock()
+
Reset_Loop:
for attempt := 0; attempt < conditionalRetryCount; attempt++ {
currentRangeID := s.getRangeID()
