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

[PULP-218] Add timeout to immediate tasks #6155

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

pedro-psb
Copy link
Member

No description provided.

@pedro-psb pedro-psb changed the title Add timeout to immediate tasks [PULP-218] Add timeout to immediate tasks Dec 16, 2024
Comment on lines 62 to 63
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(IMMEDIATE_TASK_TIMEOUT)
Copy link
Member

Choose a reason for hiding this comment

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

Oh, interesting.
This is quite close to low level process handling. I wonder if this might interfere with other uses of the signal handler.

Do you think we can instead require that all immediate tasks are async functions? We could then implement the timeout on the asyncio level with much more confidence.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think we can instead require that all immediate tasks are async functions? We could then implement the timeout on the asyncio level with much more confidence.

Yes. I dont have a good idea of how much friction this imposes, but that's definitely more safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mdellweg Hey! Can you provide an early review for the api worker part?

@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch from 6b4c39f to 138be99 Compare February 11, 2025 19:58
@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch from 138be99 to 08a9c14 Compare February 11, 2025 22:10
@pedro-psb pedro-psb linked an issue Feb 12, 2025 that may be closed by this pull request
@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch from 7eb645f to c151ecf Compare February 12, 2025 19:20
@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch 3 times, most recently from 54c86f9 to 1704eb4 Compare February 12, 2025 22:08
@pedro-psb pedro-psb marked this pull request as ready for review February 12, 2025 22:18
@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch from 1704eb4 to 88fc96d Compare February 12, 2025 22:32
loop.run_until_complete(result)
if immediate:
try:
loop.run_until_complete(asyncio.wait_for(result, timeout=IMMEDIATE_TIMEOUT))
Copy link
Member

Choose a reason for hiding this comment

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

Looks like a good first cut. But we still stop the heartbeat loop for up to 5 seconds here.

We should definitely plan on rewriting the workers in async.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should definitely plan on rewriting the workers in async.

Would you say that's a blocker (for running on foreground)?

I was trying to find a way to integrate the coroutine control yielding with the select-loop, but I'm reaching dark corners.

If that's a blocker this PR could be really about the timeout (as originally intented). The commit "wip: add timeout to supervise immediate tasks" adds a timeout to the regular task process. Maybe we could stop there.

Copy link
Member

Choose a reason for hiding this comment

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

Not necessarily. It's a certain risk. But it's nothing we cannot revert when things go bad.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe after all it's wise to split the work into smaller chunks to reduce that risk.
Ensuring that immediate tasks don't run too long is still an incremental improvement.

@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch from 6b2781e to 1b427eb Compare February 13, 2025 19:53
@mdellweg
Copy link
Member

We cannot require all immediate tasks to be async without properly deprecating it for plugins.
But we can use sync_to_async for the ones that aren't with a deprecation warning.

@pedro-psb pedro-psb force-pushed the add-timeout-to-immediate-task branch from 00a071e to e834821 Compare February 14, 2025 14:21
@pedro-psb
Copy link
Member Author

No idea why this fails only on s3:
https://github.com/pulp/pulpcore/actions/runs/13333279626/job/37242548757?pr=6155#step:14:18219

An exception does get caught...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add timeout to immediate tasks
2 participants