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

Better error handling during force shutdown #2271

Merged
merged 1 commit into from Sep 24, 2020

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented May 17, 2020

Description

Refactors tests covering shutdown behavior to be less flaky (the current tests depend on fragile sleep timing that isn't 100% deterministic), and also fixes a couple of subtle timing edge-cases around force-shutdown behavior:

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added an entry to History.md if this PR fixes a bug or adds a feature. If it doesn't need an entry to HISTORY.md, I have added [changelog skip] the pull request title.
  • I have added appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@nateberkopec nateberkopec added maintenance waiting-for-review Waiting on review from anyone labels May 21, 2020
@@ -244,19 +244,17 @@ def eagerly_finish
end # IS_JRUBY

def finish(timeout)
return true if @ready
Copy link
Member

Choose a reason for hiding this comment

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

Hm, what's the impact of changing the return value here? Any?

Copy link
Member

Choose a reason for hiding this comment

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

Just looking through the rest of the code, seems like we never checked the value.

# Returns block return value if queue is enabled, or nil if queue is not enabled.
def if_queue_requests
@queue_mutex.synchronize do
if @queue_requests
Copy link
Member

Choose a reason for hiding this comment

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

Since queue_requests is set at configure-time, I think we can move this outside the mutex, right?

def queue_client(client, timeout)
if_queue_requests do
client.set_timeout timeout
@reactor.add client
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to keep concurrency as a concern of the Reactor rather than the Server? It sort of feels like we could refactor this a little further to keep concurrency concerns out of this class.

@nateberkopec
Copy link
Member

I think my only concerns are the concurrency-awareness being added to Server when I think it hasn't had many concurrency-related reponsibilities yet. I'm wondering if we can shove all of that into Reactor instead so we keep Puma's main "concurrency-aware" classes as Reactor and Threadpool.

@nateberkopec nateberkopec added waiting-for-changes Waiting on changes from the requestor and removed waiting-for-review Waiting on review from anyone labels Jun 10, 2020
@wjordan
Copy link
Contributor Author

wjordan commented Jun 10, 2020

I'm wondering if we can shove all of that into Reactor instead so we keep Puma's main "concurrency-aware" classes as Reactor and Threadpool.

I agree, the Reactor refactoring in #2279 updates Reactor#add to better handle this edge-case where #shutdown is concurrently called, so synchronization would no longer be needed in Server itself.

If that Reactor refactoring seems reasonable, this PR might be simpler following that one (e.g., 9975355.)

@nateberkopec
Copy link
Member

Sounds good, we can block this PR on that one.

Only allow `ForceShutdown` to be raised in a thread during specific areas of the
connection-processing cycle (marked by `with_force_shutdown` blocks),
to ensure that the raised error is always rescued and handled cleanly.
Fixes an issue where the `force_shutdown_after: 0` option throws
uncaught exceptions from the threadpool on shutdown.
@wjordan
Copy link
Contributor Author

wjordan commented Sep 23, 2020

Rebased after #2377 was merged, which fixed the second issue addressed by this PR (I've crossed out that part in the PR description above). This also means that the remaining part of this PR is no longer blocked on #2279 so it's ready for another review.

@nateberkopec nateberkopec added waiting-for-review Waiting on review from anyone and removed waiting-for-changes Waiting on changes from the requestor labels Sep 23, 2020
@nateberkopec nateberkopec merged commit f4c59a0 into puma:master Sep 24, 2020
@wjordan wjordan mentioned this pull request Oct 1, 2020
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance waiting-for-review Waiting on review from anyone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants