Title: fix: Keep the metrics server running when a Gunicorn worker exits by aborgatin · Pull Request #7012 · feast-dev/feast · GitHub
Open Graph Title: fix: Keep the metrics server running when a Gunicorn worker exits by aborgatin · Pull Request #7012 · feast-dev/feast
X Title: fix: Keep the metrics server running when a Gunicorn worker exits by aborgatin · Pull Request #7012 · feast-dev/feast
Description: What this PR does / why we need it: Since #6855 the metrics server runs in a multiprocessing.Process(daemon=True) started in the Gunicorn master. Every forked worker inherits multiprocessing's registry of child processes, and at worker exit multiprocessing.util._exit_function terminates every daemon process in it. So the first worker restart (--max-requests, worker timeout, reload) sends SIGTERM to the master's metrics server, and /metrics stops responding until feast serve is restarted. Every worker exit also logs AssertionError: can only join a child process. Details and steps to reproduce in #7011. When the metrics process is started, this registers an os.register_at_fork(after_in_child=...) hook that removes it from the registry in every child forked from that process. An at-fork hook rather than a Gunicorn hook, so it also covers workers that exit before post_worker_init (e.g. a worker that fails to boot). Workers no longer terminate the metrics server; the master still terminates it on its own exit. Tested with the steps from #7011 (--max-requests 3): macOS, Python 3.12: /metrics returns 200 after the worker restarts (000 before the change), no AssertionError. Linux (python:3.12-slim, 0.67.0 with this metrics.py): 0.67.0 as released: /metrics 000 after the first worker exit. With the change, 2 workers: 19 worker exits, /metrics answered all 300 checks, no AssertionError; after stopping feast serve no metrics process is left. Which issue(s) this PR fixes: Fixes #7011 Checks I've made sure the tests are passing. (pytest sdk/python/tests/unit/test_metrics.py: 127 passed; ruff check and ruff format --check pass; mypy feast reports no errors in metrics.py) My commits are signed off (git commit -s) My PR title follows conventional commits format Testing Strategy Unit tests – TestMetricsProcessSurvivesForkedChildExit: start_metrics_server registers a daemon stand-in process (fork context, so it starts instantly on every platform), a forked child runs multiprocessing.util._exit_function() as a worker does at exit, then the test checks the process is still alive (before the change it is terminated with -SIGTERM). The /metrics HTTP checks are the end-to-end runs above. Integration tests 🤖 Generated with Claude Code
Open Graph Description: What this PR does / why we need it: Since #6855 the metrics server runs in a multiprocessing.Process(daemon=True) started in the Gunicorn master. Every forked worker inherits multiprocessing's ...
X Description: What this PR does / why we need it: Since #6855 the metrics server runs in a multiprocessing.Process(daemon=True) started in the Gunicorn master. Every forked worker inherits multiprocessing...
Opengraph URL: https://github.com/feast-dev/feast/pull/7012
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b911d6a8-861e-5ac9-3305-be3b5c2ce248 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | EAF4:61466:DF5E4B:13163F1:6AFE9256 |
| html-safe-nonce | af1e4fcfcd74ff14026c3101e57ad16af6653e9429b425caf247bf3e241df1ac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUY0OjYxNDY2OkRGNUU0QjoxMzE2M0YxOjZBRkU5MjU2IiwidmlzaXRvcl9pZCI6IjMxOTM5OTQwODQwNTgzMDUxMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8ba75a456e6a4143c90824d8fc451767c68f06a1a12b7e9391d62541adc92f54 |
| hovercard-subject-tag | pull_request:4858353431 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/feast-dev/feast/pull/7012/files |
| twitter:image | https://avatars.githubusercontent.com/u/43031807?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/43031807?s=400&v=4 |
| og:image:alt | What this PR does / why we need it: Since #6855 the metrics server runs in a multiprocessing.Process(daemon=True) started in the Gunicorn master. Every forked worker inherits multiprocessing's ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/feast-dev/feast git https://github.com/feast-dev/feast.git |
| octolytics-dimension-user_id | 57027613 |
| octolytics-dimension-user_login | feast-dev |
| octolytics-dimension-repository_id | 161133770 |
| octolytics-dimension-repository_nwo | feast-dev/feast |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 161133770 |
| octolytics-dimension-repository_network_root_nwo | feast-dev/feast |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width