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

AppServerMetrics reporting-thread fix #24967

Merged
merged 2 commits into from Sep 24, 2018
Merged

AppServerMetrics reporting-thread fix #24967

merged 2 commits into from Sep 24, 2018

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Sep 22, 2018

This PR resolves an issue with the AppServerMetrics metrics-reporting thread being shutdown by Puma, by manually spawning the reporting task in a before_block instead of implicitly when the middleware is instantiated.

The issue stems from a slight apparent difference between Puma and Unicorn in the daemonization process. While Unicorn preserves threads created by the master process, Puma shuts down any threads spawned during the app-preload process unless they are created after daemonize! occurs within the before_fork hook.

In order to access the middleware instance within the hook, I added an instance class-accessor to the middleware class. This doesn't seem ideal, but I couldn't figure any better way to access the middleware instance (since the instance is created dynamically from the Rack builder when the middleware stack is built on startup, there's no place in code we can assign the individual instance for later access). This shouldn't be a problem in practice, since there should only be a single instance of this middleware-class created per process.

Manually spawn reporting task in `before_fork` block after master process
is daemonized, to prevent reporting thread from being shutdown by Puma.
@wjordan
Copy link
Contributor Author

wjordan commented Sep 22, 2018

Confirmed on an adhoc instance that this PR results in correct metrics being reported to CloudWatch.

spawn reporting task in test
@wjordan wjordan merged commit e657624 into staging Sep 24, 2018
@wjordan wjordan deleted the app_server_metrics_fix branch September 24, 2018 19:27
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.

None yet

1 participant