Skip to content

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

Closed
@Mywifi

Description

@Mywifi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions