Skip to content

TaskDatasetServer concurrent close not blocking start/step/etc#353

Merged
jamesbraza merged 1 commit intomainfrom
concurrency-task-dataset-close
Apr 16, 2026
Merged

TaskDatasetServer concurrent close not blocking start/step/etc#353
jamesbraza merged 1 commit intomainfrom
concurrency-task-dataset-close

Conversation

@jamesbraza
Copy link
Copy Markdown
Collaborator

TaskDatasetServer's /close_old_envs previously held the self.envs protection lock across asyncio.gather(env.close ...), stalling other endpoints like /start and /step during the shutdown. This PR fixes that concurrency issues.

@jamesbraza jamesbraza self-assigned this Apr 15, 2026
Copilot AI review requested due to automatic review settings April 15, 2026 20:35
@jamesbraza jamesbraza added the bug Something isn't working label Apr 15, 2026
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 15, 2026
@jamesbraza jamesbraza changed the title TaskDatasetServer concurrent close TaskDatasetServer concurrent close not blocking start/step/etc Apr 15, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a concurrency bottleneck in TaskDatasetServer by ensuring /close_old_envs no longer holds the global self.lock while awaiting environment shutdowns, allowing other endpoints (e.g. /start, /step) to proceed during slow closes.

Changes:

  • Update /close_old_envs to remove stale envs from self.envs under lock, then release the lock before awaiting env.close() calls.
  • Refactor test client creation into a helper and add a regression test asserting /close_old_envs doesn’t block concurrent requests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/aviary/dataset_server.py Releases the server lock before awaiting slow env.close() operations in /close_old_envs.
tests/test_envs.py Adds a concurrency regression test and refactors test client creation for the dataset server endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_envs.py Outdated
Comment thread tests/test_envs.py Outdated
Copy link
Copy Markdown
Collaborator

@sidnarayanan sidnarayanan left a comment

Choose a reason for hiding this comment

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

Nice

Previously the handler held self.lock across an asyncio.gather() of
env.close() calls, stalling every lock-acquiring endpoint (/start,
/reset, /step, /close) for the duration of shutdown. Pop the stale
envs from self.envs under the lock, then release it before awaiting
the closes — matches the pattern /close already uses and prevents
handler pileups during mass cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jamesbraza jamesbraza force-pushed the concurrency-task-dataset-close branch from 799e560 to 8578ac0 Compare April 16, 2026 18:14
@jamesbraza jamesbraza merged commit 9e0a0aa into main Apr 16, 2026
9 of 10 checks passed
@jamesbraza jamesbraza deleted the concurrency-task-dataset-close branch April 16, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants