René's URL Explorer Experiment


Title: Intermittent deadlock on `feast serve` startup under gunicorn: feature-freshness thread starts pre-fork and can freeze an import lock forever · Issue #6647 · feast-dev/feast · GitHub

Open Graph Title: Intermittent deadlock on `feast serve` startup under gunicorn: feature-freshness thread starts pre-fork and can freeze an import lock forever · Issue #6647 · feast-dev/feast

X Title: Intermittent deadlock on `feast serve` startup under gunicorn: feature-freshness thread starts pre-fork and can freeze an import lock forever · Issue #6647 · feast-dev/feast

Description: Describe the bug feast serve (running under gunicorn, uvicorn_worker.UvicornWorker) can hang forever at startup with no error, no traceback, and no log output beyond "Waiting for application startup.". It's intermittent — most starts suc...

Open Graph Description: Describe the bug feast serve (running under gunicorn, uvicorn_worker.UvicornWorker) can hang forever at startup with no error, no traceback, and no log output beyond "Waiting for application startu...

X Description: Describe the bug feast serve (running under gunicorn, uvicorn_worker.UvicornWorker) can hang forever at startup with no error, no traceback, and no log output beyond "Waiting for application s...

Opengraph URL: https://github.com/feast-dev/feast/issues/6647

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Intermittent deadlock on `feast serve` startup under gunicorn: feature-freshness thread starts pre-fork and can freeze an import lock forever","articleBody":"\n## Describe the bug\n\n`feast serve` (running under gunicorn, `uvicorn_worker.UvicornWorker`) can hang forever at startup with **no error, no traceback, and no log output** beyond `\"Waiting for application startup.\"`. It's intermittent — most starts succeed, but occasionally a worker freezes permanently and never becomes ready.\n\n## Root cause\n\n`feast_metrics.start_metrics_server()` is called from `feature_server.start_server()`, which runs in the **gunicorn master process**, before `FeastServeApplication(...).run()` triggers gunicorn's `fork()` of the worker process(es).\n\n`start_metrics_server()` correctly defers CPU/memory resource monitoring to *after* the fork (there's an explicit `start_resource_monitoring=not uses_gunicorn` check, plus a `post_worker_init` hook that calls `init_worker_monitoring()`). However, it does **not** apply the same treatment to the feature-freshness thread:\n\n```python\nif _config.freshness:\n    freshness_thread = threading.Thread(\n        target=monitor_freshness, args=(store, 30), daemon=True\n    )\n    freshness_thread.start()\n```\n\nThis thread is started unconditionally in the master (whenever `feature_server.metrics.freshness` is enabled), and its very first action — with no delay — is `update_feature_freshness(store)` → `store.list_feature_views(...)`, which lazily builds the registry for the first time. For registry backends that need a lazy DBAPI import (e.g. the SQL registry importing `pymysql` via SQLAlchemy's `create_engine()`), this means a background thread in the gunicorn master may be **mid-import**, holding CPython's per-module import lock, at the exact moment gunicorn forks a worker.\n\nPOSIX `fork()` only duplicates the calling thread into the child process — every other thread that existed in the parent (including this freshness thread) simply ceases to exist in the worker. If the fork happens while that thread holds a module's import lock, the lock is left permanently in the \"locked\"/`_initializing` state inside the new worker, and there is no longer any thread anywhere that can finish that import and release it. When the worker's own FastAPI startup later tries to build its own registry and hits the same import, it deadlocks forever.\n\nThis matches a known general class of hazard (fork() + threads + an in-flight import lock — see e.g. https://bugs.python.org/issue6380), and it explains the intermittency exactly: it only manifests if the fork lands inside that narrow timing window.\n\nWe confirmed this live by attaching `py-spy` to a genuinely frozen worker process and dumping its stack — the main thread was blocked acquiring CPython's per-module import lock inside `SQLAlchemy`'s lazy `import_dbapi()` (dialects/mysql/pymysql.py), called from `SqlRegistry.__init__` → `feature_store.py`'s `registry` property → `refresh_registry()` → `feature_server.py`'s `async_refresh()` → the FastAPI `lifespan`.\n\nWe also verified against CPython's actual `importlib._bootstrap._find_and_load` that the per-module import lock is **only** acquired if a module is missing from `sys.modules` or still mid-initialization — once a module has fully finished importing, every later import statement, from any thread, before or after any number of forks, returns the cached module without ever touching the lock again. This is why the freshness thread's *pre-fork* timing is what makes it dangerous, and it points at the fix.\n\n## To Reproduce\n\n1. Configure a registry backend that performs a lazy import on first use (e.g. `registry_type: sql` with a MySQL connection string, which lazily imports `pymysql` via SQLAlchemy).\n2. Enable `feature_server.metrics.freshness: true` in `feature_store.yaml`.\n3. Run `feast serve --metrics` under gunicorn (Linux, non-Windows path) with 1+ workers.\n4. Restart the process repeatedly (e.g. in a container orchestrator that recycles the pod/process on every deploy or crash). Occasionally — timing-dependent, not consistently reproducible on demand — a worker will hang forever at `\"Waiting for application startup.\"` with zero output.\n\n## Expected behavior\n\nThe feature-freshness thread (and ideally anything else `start_metrics_server()` spawns pre-fork that can trigger a lazy import) should be deferred to run after gunicorn forks its workers, the same way resource monitoring already is — e.g. via the existing `post_worker_init` hook — rather than starting unconditionally in the master before the fork.\n\n## Workaround\n\nForce the DBAPI driver (e.g. `pymysql`) to finish importing once, synchronously, as the very first statement of the process — before `feast`'s CLI runs, before any thread exists, and before gunicorn forks anything. A tiny wrapper around the CLI entrypoint works:\n\n```python\nimport pymysql  # must be first — see explanation above\nimport sys\nfrom feast.cli.cli import cli\n\nif __name__ == \"__main__\":\n    sys.exit(cli())\n```\n\n...invoked instead of the `feast` console script (e.g. `python entrypoint.py serve ...`). This is unrelated to thread timing luck — once the module is fully imported, the import lock is never touched again for it, regardless of what any other thread does afterward.\n\n## Environment\n\n- feast version: 0.62.0\n- Python: 3.11\n- OS: Linux (containerized), gunicorn + `uvicorn_worker.UvicornWorker`\n- Registry: SQL registry (`registry_type: sql`, MySQL via pymysql)\n","author":{"url":"https://github.com/casaar97","@type":"Person","name":"casaar97"},"datePublished":"2026-07-27T11:05:56Z","url":"https://github.com/feast-dev/feast/issues/6647"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a2181178-607d-db45-55f8-d54d7e68546a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8D9E:20D634:DE2B4C:1285410:6AFE981B
html-safe-nonce8841bef4276b95bb20c51ae93f59967ec88b873c90ac0330c89d05e47507fd7b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDlFOjIwRDYzNDpERTJCNEM6MTI4NTQxMDo2QUZFOTgxQiIsInZpc2l0b3JfaWQiOiI0OTAyNjM4ODAwMDQ5NDQ0ODkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1ef5449f607c42160425e4bf7ac24617745aadd40f2589524a694840460d7e88
hovercard-subject-tagissue:4987215344
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/feast-dev/feast/6647/issue_layout
twitter:imagehttps://opengraph.githubassets.com/512ff466daa8273e63d3a4b225147c5a360cd17a0cefec5872be6781d2407643/feast-dev/feast/issues/6647
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/512ff466daa8273e63d3a4b225147c5a360cd17a0cefec5872be6781d2407643/feast-dev/feast/issues/6647
og:image:altDescribe the bug feast serve (running under gunicorn, uvicorn_worker.UvicornWorker) can hang forever at startup with no error, no traceback, and no log output beyond "Waiting for application startu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecasaar97
hostnamegithub.com
expected-hostnamegithub.com
Noneb3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86
turbo-cache-controlno-preview
go-importgithub.com/feast-dev/feast git https://github.com/feast-dev/feast.git
octolytics-dimension-user_id57027613
octolytics-dimension-user_loginfeast-dev
octolytics-dimension-repository_id161133770
octolytics-dimension-repository_nwofeast-dev/feast
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id161133770
octolytics-dimension-repository_network_root_nwofeast-dev/feast
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4a10310af51a1bfffbedc4fd81cb582acf0cb0ff
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/feast-dev/feast/issues/6647#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffeast-dev%2Ffeast%2Fissues%2F6647
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffeast-dev%2Ffeast%2Fissues%2F6647
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=feast-dev%2Ffeast
Reloadhttps://github.com/feast-dev/feast/issues/6647
Reloadhttps://github.com/feast-dev/feast/issues/6647
Reloadhttps://github.com/feast-dev/feast/issues/6647
feast-devhttps://github.com/feast-dev
feasthttps://github.com/feast-dev/feast
Codehttps://github.com/feast-dev/feast
Issues223 (223)https://github.com/feast-dev/feast/issues
Pull requests143 (143)https://github.com/feast-dev/feast/pulls
Discussionshttps://github.com/feast-dev/feast/discussions
Actionshttps://github.com/feast-dev/feast/actions
Security and quality1 (1)https://github.com/feast-dev/feast/security
Insightshttps://github.com/feast-dev/feast/insights
https://github.com/feast-dev/feast
New issuehttps://github.com/login?return_to=https://github.com/feast-dev/feast/issues/6647
New issuehttps://github.com/login?return_to=https://github.com/feast-dev/feast/issues/6647
#6648https://github.com/feast-dev/feast/pull/6648
Intermittent deadlock on feast serve startup under gunicorn: feature-freshness thread starts pre-fork and can freeze an import lock foreverhttps://github.com/feast-dev/feast/issues/6647#top
#6648https://github.com/feast-dev/feast/pull/6648
https://github.com/casaar97
casaar97https://github.com/casaar97
on Jul 27, 2026https://github.com/feast-dev/feast/issues/6647#issue-4987215344
https://bugs.python.org/issue6380https://bugs.python.org/issue6380
casaar97https://github.com/casaar97
on Jul 27, 2026https://github.com/feast-dev/feast/issues/6647#event-28540297280
fix: Defer feature-freshness thread to post-fork to avoid Gunicorn de…https://github.com/casaar97/feast/commit/597a845d79a922eada468a6cac759e61ba5db942
https://docs.github.com/articles/closing-issues-via-commit-messages
597a845https://github.com/casaar97/feast/commit/597a845d79a922eada468a6cac759e61ba5db942
fix: Defer feature-freshness thread to post-fork to avoid Gunicorn de…https://github.com/casaar97/feast/commit/537675154ff8351f05c1c5dfff79adff7a6ede73
https://docs.github.com/articles/closing-issues-via-commit-messages
5376751https://github.com/casaar97/feast/commit/537675154ff8351f05c1c5dfff79adff7a6ede73
jyejarehttps://github.com/jyejare
completedhttps://github.com/feast-dev/feast/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#6648https://github.com/feast-dev/feast/pull/6648
on Jul 27, 2026https://github.com/feast-dev/feast/issues/6647#event-28552219495
pullhttps://github.com/apps/pull
on Jul 27, 2026https://github.com/feast-dev/feast/issues/6647#event-28555422153
fix: Defer feature-freshness thread to post-fork to avoid Gunicorn de…https://github.com/digitty-forks/feast/commit/104ad10403e4e7dcb27145a86b2523c1c4639612
https://docs.github.com/articles/closing-issues-via-commit-messages
104ad10https://github.com/digitty-forks/feast/commit/104ad10403e4e7dcb27145a86b2523c1c4639612
jyejarehttps://github.com/jyejare
on Jul 28, 2026https://github.com/feast-dev/feast/issues/6647#event-28592362168
chore: Manually Sync upstream master to midstream as auto-sync failed (…https://github.com/opendatahub-io/feast/commit/afff726ba8f892dfd5516ad77491890fb99cdb47
…https://github.com/opendatahub-io/feast/pull/166
https://docs.github.com/articles/closing-issues-via-commit-messages
afff726https://github.com/opendatahub-io/feast/commit/afff726ba8f892dfd5516ad77491890fb99cdb47
aniketpaluhttps://github.com/aniketpalu
on Jul 28, 2026https://github.com/feast-dev/feast/issues/6647#event-28593062498
fix: Defer feature-freshness thread to post-fork to avoid Gunicorn de…https://github.com/aniketpalu/feast/commit/ac4b5e56f27ccad576d1fbfbeb8f6a941a451413
https://docs.github.com/articles/closing-issues-via-commit-messages
ac4b5e5https://github.com/aniketpalu/feast/commit/ac4b5e56f27ccad576d1fbfbeb8f6a941a451413
franciscojavierarceohttps://github.com/franciscojavierarceo
on Aug 21, 2026https://github.com/feast-dev/feast/issues/6647#event-29781433618
chore(release): release 0.66.0https://github.com/feast-dev/feast/commit/1d5be950cf718a674cb01eaf0fd0ad6f0a4c6335
1d5be95https://github.com/feast-dev/feast/commit/1d5be950cf718a674cb01eaf0fd0ad6f0a4c6335
Michie-hubhttps://github.com/Michie-hub
on Aug 31, 2026https://github.com/feast-dev/feast/issues/6647#event-30282805956
chore(release): release 0.66.0https://github.com/Michie-hub/feast/commit/a29c9231976fd7c68e51570047f9517f06579041
a29c923https://github.com/Michie-hub/feast/commit/a29c9231976fd7c68e51570047f9517f06579041
Sign up for freehttps://github.com/signup?return_to=https://github.com/feast-dev/feast/issues/6647
Sign in to commenthttps://github.com/login?return_to=https://github.com/feast-dev/feast/issues/6647
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.