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

Fix race condition during cache eviction #1210

Conversation

Quinn-With-Two-Ns
Copy link
Contributor

Fix race condition during cache eviction

see #1209 for more details

@Quinn-With-Two-Ns Quinn-With-Two-Ns marked this pull request as ready for review August 25, 2023 17:39
@Quinn-With-Two-Ns Quinn-With-Two-Ns requested a review from a team as a code owner August 25, 2023 17:39
@@ -638,6 +638,7 @@ func (wc *workflowEnvironmentInterceptor) ExecuteActivity(ctx Context, typeName

if cancellable {
cancellationCallback.fn = func(v interface{}, more bool) bool {
assertNotInReadOnlyStateCancellation(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand exactly. Are we using panics for control flow here? Is there any other way to not do stuff during coroutine exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's using panics for control flow as much as any of our other read only state checks or non determinism checks are.

Copy link
Member

@cretz cretz Aug 28, 2023

Choose a reason for hiding this comment

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

I assume what happens is we recover() in the panic handler but there is no workflow task to fail so it does nothing?

Is there any other/clearer way to not do stuff during coroutine exit? Can this be moved to where cancellationCallback.fn is invoked instead of put in each callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assertion is almost the same as any of our other read only assertions we have in the Go SDK so it should be implemented as such.

Copy link
Member

Choose a reason for hiding this comment

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

Is there any other/clearer way to not do stuff during coroutine exit? Can this be moved to where cancellationCallback.fn is invoked instead of put in each callback?

(just want to confirm that there is no better way than panicking at the beginning of every cancel callback)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, again this is the same thing as any of our other read only checks we added or non determinism. We always panic in those cases because it's the only option.

@@ -664,6 +664,24 @@ func assertNotInReadOnlyState(ctx Context) {
}
}

func assertNotInReadOnlyStateCancellation(ctx Context) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this "read only" the same definition as used for query and update validators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, as is documented in the function we can't use the normal check in cancellation because of how the Go SDK implemented workflow cancellation

Copy link
Member

Choose a reason for hiding this comment

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

Hrmm, I wonder if there's another term for read-only to not be confused with the query/update-validator definition. Either way, just naming, no biggie.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I named them similar because it is basically the same validation for the same purpose.

@Quinn-With-Two-Ns
Copy link
Contributor Author

I'll note even without the race condition this PR is still needed because currently contexts can be cancelled in a read only context which may generate commands and that is not valid.

@@ -664,6 +664,24 @@ func assertNotInReadOnlyState(ctx Context) {
}
}

func assertNotInReadOnlyStateCancellation(ctx Context) {
Copy link
Member

Choose a reason for hiding this comment

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

One more question I forgot to ask before I mark approved. Can you think of any case where this can break a working workflow today? I can't, just checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I can't think of any

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.

2 participants