Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic fix: no version histories is mutable state #1

Conversation

dkrotx
Copy link
Owner

@dkrotx dkrotx commented Jan 2, 2025

What changed?
Handle error if version histories is nil instead of calling a method (GetCurrentVersionHistory) on a nil pointer.
While returning an empty version histories might look like a good alternative, is not since everywhere in code we expect versions to be not empty. In addition, version histories also has index and it should always be valid (0 refers to histories[0]).

Why?
Because of panics in Uber production.

Having no version histories is considered OK by getMutableState which has:

if versionHistories != nil {
        retResp.VersionHistories = versionHistories.ToInternalType()
}

Which means, PollMutableState/GetMutableState should not panic on this. It is now returning error.
Could make it even better and handle case when initially there were no versions history, and then appeared, but:
a) an error instead of panic-ing is already better b) this will complicate tests
c) still not sure how valid this case is (isn't that a corrupted execution?)

How did you test it?
Added a new unit-test

Potential risks

Release notes

Documentation Changes

Having no version histories is considered OK by `getMutableState` which
has:
```
if versionHistories != nil {
        retResp.VersionHistories = versionHistories.ToInternalType()
}
```

Which means, PollMutableState/GetMutableState should not panic on this.
It is now returning error.
Could make it even better and handle case when initially there were no
versions history, and then appeared, but:
a) an error instead of panic-ing is already better
b) this will complicate tests
c) still not sure how valid this case is (isn't that a corrupted
execution?)
@@ -160,6 +160,15 @@ func (e *historyEngineImpl) getMutableStateOrLongPoll(
return nil, err
}

if response.GetVersionHistories() == nil {
Copy link

@Groxx Groxx Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 since .GetX() is generally a nil-hiding thing, tbh I think this might be worth changing to response.VersionHistories.

in practice this is fine because:

func (v *GetMutableStateResponse) GetVersionHistories() (o *VersionHistories) {
	if v != nil && v.VersionHistories != nil {
		return v.VersionHistories
	}
	return
}

but that's sorta abnormal/unexpected for those methods imo. it'd make sense if it was a **VersionHistories, but it's just weird code otherwise (it amounts to if v != nil { return v.VersionHistories } but it's generated code so it's not simplified)

@dkrotx dkrotx changed the base branch from cadence-get_mutable_state_or_polling-refactoring to master January 3, 2025 07:44
@dkrotx dkrotx changed the base branch from master to cadence-get_mutable_state_or_polling-refactoring January 3, 2025 07:45
@dkrotx
Copy link
Owner Author

dkrotx commented Jan 3, 2025

Transitioned to cadence-workflow#6589 instead

@dkrotx dkrotx closed this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants