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 Aggregate initialization races #287

Merged

Conversation

uberbrodt
Copy link
Contributor

It's possible for an Aggregate to receive an command before it's state
is initialized. This leads to execute/2 handlers receiving nil for the
aggregate state. It appears to happen more often when using a
distributed process registry. The fix is to replace the casts in the
init/1 handler with a chain of handle_continue/2 callbacks that are
guaranteed to complete before the first message is handled.

COMPATIBILITY NOTE: GenServer.handle_continue/2 requires OTP-21 or greater

It's possible for an Aggregate to receive an command before it's state
is initialized. This leads to execute/2 handlers receiving `nil` for the
aggregate state. It appears to happen more often when using a
distributed process registry. The fix is to replace the casts in the
init/1 handler with a chain of handle_continue/2 callbacks that are
guaranteed to complete before the first message is handled.

COMPATIBILITY NOTE: GenServer.handle_continue/2 requires OTP-21 or greater
@slashdotdash
Copy link
Member

Thanks for the pull request @uberbrodt.

@slashdotdash slashdotdash merged commit f691fb6 into commanded:master Jun 10, 2019
slashdotdash added a commit that referenced this pull request Jun 10, 2019
Remove obsolete `handle_cast/2` functions replaced by `handle_continue/2`.
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