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

State Model Overwrite Detection #40

Open
ztnel opened this issue Jun 23, 2022 · 1 comment
Open

State Model Overwrite Detection #40

ztnel opened this issue Jun 23, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request feature feature request

Comments

@ztnel
Copy link
Owner

ztnel commented Jun 23, 2022

if we assign an internal commit id to each state model we can provide validation that the candidate commit state model is up to date with myosin's internal state model and will not overwrite any properties unintentionally. This can happen in a multithreaded environment where the checked out copy of the state model is out of date with the current copy:

Consider this example which does not use the state lock properly:

with State() as state:
   model = state.checkout(Model)
model.property = some_long_operation()
with State() as state:
   state.commit(model)

In a multithreaded environment where Model is being updated elsewhere the commit statement here will overwrite all recent property changes except for the property value. The way to solve this of course is to keep all checkout and commit operations within the same state lock session:

with State() as state:
   model = state.checkout(Model)
   model.property = some_long_operation()
   state.commit(model)

But to an end developer debugging their application having some internal detection and logging messages may help them identify this mistake.

@ztnel ztnel added enhancement New feature or request feature feature request labels Jun 23, 2022
@ztnel ztnel changed the title Unsafe Memory Access Detection Memory Overwrite Detection Jun 23, 2022
@ztnel ztnel changed the title Memory Overwrite Detection State Model Overwrite Detection Jun 23, 2022
@ztnel
Copy link
Owner Author

ztnel commented Aug 28, 2022

This can be solved using a private __context__ hash property which is set by the state context on checkout. Before a commit is made the__context__ hash of the commit instance can be checked against the current instance __context__ to ensure the model is from a checkout within this context.

@ztnel ztnel self-assigned this Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature feature request
Projects
None yet
Development

No branches or pull requests

1 participant