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

Process: properly cleanup when exception in state transition #5697

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Oct 12, 2022

Fixes #2861
Fixes #3334

If a process would hit an exception during a state transition, the node would not always be cleaned up properly. For example, when a process registers invalid outputs, the process would except in update_outputs which is called by on_entered which is called once the process has entered a new state.

This exception would not be dealt with, skipping the code that is responsible for updating the process state on the node. This would lead to the node of the excepted node to still show the previous incorrect state. Typically, users would see processes as Running in the output of verdi process list. This is because that value is taken from the process_state attribute, but this simply contained the incorrect state.

The solution requires a fix in plumpy, which was released with v0.21. but it also requires an update in update_node_state of the Process class to make sure the set_process_state call is made before the update_outputs which is prone to excepting in the case of invalid outputs having been registered by the process implementation.

@sphuber sphuber added the pr/blocked PR is blocked by another PR that should be merged first label Oct 12, 2022
@sphuber
Copy link
Contributor Author

sphuber commented Oct 12, 2022

Note this is blocked because it requires a fix in plumpy provided by this PR aiidateam/plumpy#240

@sphuber sphuber force-pushed the fix/2861/exception-in-state-transition branch from 2668c0c to c9e9240 Compare October 25, 2022 07:57
@sphuber sphuber force-pushed the fix/2861/exception-in-state-transition branch 4 times, most recently from 193dded to d837c97 Compare November 21, 2022 10:21
@sphuber sphuber removed the pr/blocked PR is blocked by another PR that should be merged first label Nov 21, 2022
@sphuber sphuber force-pushed the fix/2861/exception-in-state-transition branch 2 times, most recently from 3086fb9 to b5cda38 Compare November 22, 2022 11:54
@sphuber sphuber force-pushed the fix/2861/exception-in-state-transition branch from b5cda38 to c9d6f0e Compare November 28, 2022 10:31
@sphuber
Copy link
Contributor Author

sphuber commented Nov 28, 2022

Anyone would like to review this? Otherwise I will merge this soon

@unkcpz
Copy link
Member

unkcpz commented Nov 28, 2022

@sphuber I'll give it a look now.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

@sphuber thanks! Only a minor request, but not very important.

self.node.set_process_state(state.LABEL)
self.update_outputs()
Copy link
Member

Choose a reason for hiding this comment

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

Not important, might be more clear move update_outputs to on_entered? I am quite surprised to realize that every state transfer will call update_outputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can see if we can move this to something like on_terminate so as to only do it once. Not sure if this would break anything but it should be more performant. Will have a look tomorrow.

If a process would hit an exception during a state transition, the node
would not always be cleaned up properly. For example, when a process
registers invalid outputs, the process would except in `update_outputs`
which is called by `on_entered` which is called once the process has
entered a new state.

This exception would not be dealt with, skipping the code that is
responsible for updating the process state on the node. This would lead
to the node of the excepted node to still show the previous incorrect
state. Typically, users would see processes as `Running` in the output
of `verdi process list`. This is because that value is taken from the
`process_state` attribute, but this simply contained the incorrect
state.

The solution requires a fix in `plumpy`, which was released with
`v0.21.1` but it also requires an update in `update_node_state` of the
`Process` class to make sure the `set_process_state` call is made before
the `update_outputs` which is prone to excepting in the case of invalid
outputs having been registered by the process implementation.
@sphuber sphuber force-pushed the fix/2861/exception-in-state-transition branch from c9d6f0e to 5b00a7d Compare November 28, 2022 22:20
@sphuber sphuber merged commit a7be795 into aiidateam:main Nov 28, 2022
@sphuber sphuber deleted the fix/2861/exception-in-state-transition branch November 28, 2022 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants