Skip to content

Commit

Permalink
Fix: Stopping executions could be returned
Browse files Browse the repository at this point in the history
Calling `get_running_vm(...)` could return an execution that is in a stopping state, causing issues in the next steps of the process.
  • Loading branch information
hoh committed Mar 5, 2024
1 parent d22950f commit ec72c9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/aleph/vm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def is_running(self):
else self.systemd_manager.is_service_active(self.controller_service)
)

@property
def is_stopping(self) -> bool:
return bool(self.times.stopping_at and not self.times.stopped_at)

Check warning on line 95 in src/aleph/vm/models.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/models.py#L95

Added line #L95 was not covered by tests

@property
def is_program(self):
return isinstance(self.message, ProgramContent)
Expand Down
2 changes: 1 addition & 1 deletion src/aleph/vm/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get_unique_vm_id(self) -> int:
async def get_running_vm(self, vm_hash: ItemHash) -> Optional[VmExecution]:
"""Return a running VM or None. Disables the VM expiration task."""
execution = self.executions.get(vm_hash)
if execution and execution.is_running:
if execution and execution.is_running and not execution.is_stopping:
execution.cancel_expiration()
return execution
else:
Expand Down

0 comments on commit ec72c9b

Please sign in to comment.