fix: keep startup alive when gradio's localhost probe times out on large UIs - #2110
Open
saintorphan wants to merge 1 commit into
Open
saintorphan wants to merge 1 commit into
saintorphan wants to merge 1 commit into
Conversation
…rge UIs gradio 5.29's demo.launch() probes HEAD / with httpx.head(timeout=3) x5 and aborts with 'When localhost is not accessible, a shareable link must be created' when all five fail. Serving / deep-copies the whole Blocks config and filters components per page with an O(N^2) list-membership test, so first-response time grows super-linearly with component count; WanGP's base UI plus a couple of plugins crosses 3s on slower machines and startup dies even though the server is healthy (reported on Pinokio/Windows with two plugins enabled - disabling plugins 'fixes' it by shrinking the UI). Patch the probe before demo.launch(): after the stock check gives up, retry loopback URLs once with a 60s timeout and proxies bypassed. Share-tunnel polling keeps stock behavior; a dead localhost still fails fast (connection-refused returns immediately in both passes). Sentinels coordinate with the identical shims already shipped in the ImageSuite and Prompt Library plugins so exactly one probe patch installs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WanGP can crash at startup with:
This was reported by a Pinokio/Windows user who had just enabled two plugins (ImageSuite + Prompt Library); disabling the plugins in
wgp_config.jsonmade it start again. Nothing was wrong with their network — the trigger is UI size.Root cause
Gradio 5.29's
launch()verifies localhost by probingHEAD /withhttpx.head(timeout=3), 5 attempts. But serving/deep-copies the entire Blocks config and filters components per page withcomponent["id"] in config["page"][page]["components"]— membership tests against a plain list, i.e. O(N²) in component count (gradioroutes.py, still present on gradio main).Measured per-request cost of the
/handler on a fast Linux box (gradio 5.29.0):A plugin-free synthetic Blocks app at ~32k components reproduces the exact crash on a fast machine; slower Windows machines fail at far lower counts. WanGP's base UI plus a couple of plugin tabs is enough to cross the threshold — which is why "disable plugins" looks like a fix.
The same mechanism also explains intermittent sightings on fast machines without plugins: the probe allows five attempts of exactly 3s over a ~17s window at the busiest moment of startup. A borderline first response (WanGP's base UI alone costs a second or two) plus one unlucky burst of contention in that window — first-request template compile, model preloading, antivirus scanning freshly-touched checkpoints — pushes all five attempts over. Deterministic for big-UI setups, a race for everyone else.
Fix
Patch
gradio.networking.url_okjust beforedemo.launch(): run the stock probe first, unchanged; only when it gives up, retry loopback URLs only once with a 60s timeout andtrust_env=False(a system HTTP proxy must not intercept a localhost probe — proxies are the other classic trigger of this same error).Properties:
while not networking.url_ok(self.share_url)) is untouched: patience applies to loopback URLs only.Verified against gradio 5.29.0: the 32k-component app that crashes stock
launch()starts successfully with the patch, and both plugin shims correctly back off when the host patch is present.The real long-term fix is one line in gradio's
routes.py(set(...)around the page-membership lists); I'll file that upstream separately. This patch keeps WanGP startable in the meantime and remains harmless once gradio fixes it.