Skip to content

Fix race condition: handle already completed processes - #470

Closed
LudovicoRighi wants to merge 4 commits into
masterfrom
fix-race-timeout
Closed

Fix race condition: handle already completed processes#470
LudovicoRighi wants to merge 4 commits into
masterfrom
fix-race-timeout

Conversation

@LudovicoRighi

@LudovicoRighi LudovicoRighi commented Jun 24, 2025

Copy link
Copy Markdown
Collaborator

While I was doing some final testing, I noticed this race condition. (See timeout1 job runs in Apsis).

2025-06-24T14:22:14.454 apsis.program.procstar.agent E procstar
Traceback (most recent call last):
  File "/home/lrighi/apsis/python/apsis/program/procstar/agent.py", line 532, in updates
    async for update in self.proc.updates:
  File "/space/asd/conda7/envs/prod7-20250624-009/lib/python3.10/site-packages/procstar/agent/proc.py", line 155, in updates
    raise AgentMessageError(msg, err)
procstar.agent.proc.AgentMessageError: agent error response to message: no process
2025-06-24T14:22:14.454 apsis.run_log            I r2: error: procstar: agent error response to message: no process

I've added another test for this:

without the change

FAILED test/int/procstar/test_timeout.py::test_timeout_with_delayed_reconnect_process_completed[timeout-success] - AssertionError: assert 'failure' == 'success'
  
  - success
  + failure
FAILED test/int/procstar/test_timeout.py::test_timeout_with_delayed_reconnect_process_completed[timeout-shell-success] - AssertionError: assert 'failure' == 'success'
  
  - success
  + failure
FAILED test/int/procstar/test_timeout.py::test_timeout_with_delayed_reconnect_process_completed[timeout-error-failure] - AssertionError: assert 'error' == 'failure'
  
  - failure
  + error

with the change:

test/int/procstar/test_timeout.py::test_timeout_with_delayed_reconnect_process_completed[timeout-success] PASSED                        [ 33%]
test/int/procstar/test_timeout.py::test_timeout_with_delayed_reconnect_process_completed[timeout-shell-success] PASSED                  [ 66%]
test/int/procstar/test_timeout.py::test_timeout_with_delayed_reconnect_process_completed[timeout-error-failure] PASSED                  [100%]

@LudovicoRighi
LudovicoRighi force-pushed the fix-race-timeout branch 2 times, most recently from 730a81d to 616111c Compare June 24, 2025 13:33
@LudovicoRighi LudovicoRighi changed the title Fix race condition Fix race condition: handle already completed processes Jun 24, 2025
@LudovicoRighi
LudovicoRighi force-pushed the fix-race-timeout branch 2 times, most recently from 2d88334 to e744eec Compare June 24, 2025 13:39

@gusostow gusostow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this issue specific to timeouts, or for any job that terminated while apsis down. If it's specific to timeouts I don't understand why.

log.debug("expected final FdData")
except AgentMessageError as exc:
if "no process" in str(exc):
log.info(f"{self.run_id}: could not get final output; process already gone")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want to swallow all agent message errors, or just the no process ones?

Comment thread python/apsis/program/procstar/agent.py Outdated
meta["stop"] = {"signals": [ s.name for s in self.stop_signals ]}

if res.status.exit_code == 0 and not self.timed_out:
if res.status.exit_code == 0 and res.status.signal is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So you want timed out jobs that exit 0 to be marked as success? Is this related to the bugfix?

@LudovicoRighi LudovicoRighi Jun 26, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You're right, that's not correct. I need to take a better look; for the moment, I've:

  • restored that condition e436b23
    • (this will make test_timeout_with_delayed_reconnect_process_completed to fail; I'll try to fix)
  • and added a test case for that kind of jobs d49411d

)
def test_timeout_with_delayed_reconnect_process_completed(job_name, expected_state):
"""
Tests that when Apsis is down long enough for a process to complete naturally,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe describe what the race condition is

@LudovicoRighi

Copy link
Copy Markdown
Collaborator Author

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.

3 participants