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

Fix Infinite Loading When Localhost is Unreachable in Startup Events #10729

Closed
Mywifi opened this issue Mar 5, 2025 · 2 comments · Fixed by #10739
Closed

Fix Infinite Loading When Localhost is Unreachable in Startup Events #10729

Mywifi opened this issue Mar 5, 2025 · 2 comments · Fixed by #10739
Labels
bug Something isn't working

Comments

@Mywifi
Copy link
Contributor

Mywifi commented Mar 5, 2025

I’m running a project using Gradio and encountered the following error in the log:

"When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost."

I need my proxy enabled, so I decided to set share=True and restart the program. However, the issue is that when I open the webpage and click the Gradio dropdown component, another Gradio component—which depends on the dropdown’s change event to trigger—keeps loading indefinitely.

I spent a lot of time troubleshooting this, and I finally found the reason:

gradio/blocks.py#L2650

httpx.get(
    f"{self.local_api_url}startup-events",
    verify=ssl_verify,
    timeout=None,
)

This project uses the code above to run startup events. However, when localhost is inaccessible, the request fails, and the startup events are not running.

When I click the dropdown component, it sends a request to the server, which then pushes an event to the queue. But since the startup events haven’t been executed, the queue isn’t processed, causing the webpage to keep loading forever.

Solution:
Raise an error when localhost is inaccessible and print the error message to the console. This way, users can see the error and address the issue.

resp = httpx.get(
    f"{self.local_api_url}startup-events",
    verify=ssl_verify,
    timeout=None,
)
if resp.status_code != 200:
    raise Exception(f"startup events failed, status code: {resp.status_code}, url: {resp.url}")

Setting share=True doesn’t actually solve the problem because the startup events still require a request to the server via localhost.

@abidlabs
Copy link
Member

abidlabs commented Mar 5, 2025

Thanks @Mywifi for creating this issue. Would you like to open a PR with the fix?

@Mywifi
Copy link
Contributor Author

Mywifi commented Mar 6, 2025

Thanks @abidlabs, opened a new PR: #10739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants