Skip to content

Commit

Permalink
Fix nil mutablestatebuilder panic issue in historyBuilder entities (#…
Browse files Browse the repository at this point in the history
…6669)

What changed?

Always populate mutablestatebuilder field in HistoryBuilder entities

Why?

Every HistoryBuilder needs to have MutableStateBuilder to ensure adding events are applicable.

How did you test it?

deployed in a testing environment and passed all tests and no alerts
  • Loading branch information
shijiesheng committed Feb 13, 2025
1 parent b40435f commit 65199de
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions service/history/execution/history_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ func NewHistoryBuilder(msBuilder MutableState) *HistoryBuilder {
}

// NewHistoryBuilderFromEvents creates a new history builder based on the given workflow history events
func NewHistoryBuilderFromEvents(history []*types.HistoryEvent) *HistoryBuilder {
func NewHistoryBuilderFromEvents(history []*types.HistoryEvent, msBuilder MutableState) *HistoryBuilder {
return &HistoryBuilder{
history: history,
history: history,
msBuilder: msBuilder,
}
}

Expand Down
2 changes: 1 addition & 1 deletion service/history/execution/state_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (b *stateBuilderImpl) ApplyEvents(
b.mutableState.GetExecutionInfo().SetLastFirstEventID(firstEvent.ID)
b.mutableState.GetExecutionInfo().SetNextEventID(lastEvent.ID + 1)

b.mutableState.SetHistoryBuilder(NewHistoryBuilderFromEvents(history))
b.mutableState.SetHistoryBuilder(NewHistoryBuilderFromEvents(history, b.mutableState))

return newRunMutableStateBuilder, nil
}
Expand Down
2 changes: 1 addition & 1 deletion service/history/execution/state_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *stateBuilderSuite) mockUpdateVersion(events ...*types.HistoryEvent) {
for _, event := range events {
s.mockMutableState.EXPECT().UpdateCurrentVersion(event.Version, true).Times(1)
}
s.mockMutableState.EXPECT().SetHistoryBuilder(NewHistoryBuilderFromEvents(events)).Times(1)
s.mockMutableState.EXPECT().SetHistoryBuilder(NewHistoryBuilderFromEvents(events, s.mockMutableState)).Times(1)
}

func (s *stateBuilderSuite) toHistory(events ...*types.HistoryEvent) []*types.HistoryEvent {
Expand Down

0 comments on commit 65199de

Please sign in to comment.