gradio: Random connection errors in gradio 4

Describe the bug

Getting random connection errors in gradio 4 not seen in gradio 3

https://github.com/h2oai/h2ogpt/issues/1439

Have you searched existing issues? šŸ”Ž

  • I have searched and found no existing issues

Reproduction

No repro yet, happens randomly. I shared dev console after hit.

Screenshot

image

image

Nothing at all appears in the logs. Seems like pure UI issue.

Logs

No response

System Info

gradio 4.19 but seen for all gradio 4

Severity

Blocking usage of gradio

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Reactions: 2
  • Comments: 25 (10 by maintainers)

Most upvoted comments

oh thank god, haha alright Iā€™ll clean up the PR!

Iā€™ve tried to see if there is some pattern, but I canā€™t find it. I shared the dev console. I think the gradio UI needs to show more information about what happened and why. ā€œConnection errorā€ raised is too generic. I canā€™t tell from dev console where in UI code it happened, I just end up in a place where the error is printed.

I can reproduce it on my own computer (localhost, without using the network) by adding more elements:

import random
import time

import gradio as gr

def make_number():
    time.sleep(random.random() * 0.01)
    return str(random.randint(0, 8))

with gr.Blocks() as demo:
    with gr.Tab():
        msg1 = gr.Textbox()
        msg2 = gr.Textbox()
        msg3 = gr.Textbox()
        msg4 = gr.Textbox()
        msg5 = gr.Textbox()
        msg6 = gr.Textbox()
        msg7 = gr.Textbox()
        msg8 = gr.Textbox()
        msg9 = gr.Textbox()
        msg10 = gr.Textbox()
        msg11 = gr.Textbox()
        msg12 = gr.Textbox()

    with gr.Tab():
        msg13 = gr.Textbox()
        msg14 = gr.Textbox()
        msg15 = gr.Textbox()
        msg16 = gr.Textbox()
        msg17 = gr.Textbox()
        msg18 = gr.Textbox()
        msg19 = gr.Textbox()
        msg20 = gr.Textbox()
        msg21 = gr.Textbox()
        msg22 = gr.Textbox()
        msg23 = gr.Textbox()
        msg24 = gr.Textbox()

    demo.load(make_number, None, msg1, show_progress=False)
    demo.load(make_number, None, msg2, show_progress=False)
    demo.load(make_number, None, msg3, show_progress=False)
    demo.load(make_number, None, msg4, show_progress=False)
    demo.load(make_number, None, msg5, show_progress=False)
    demo.load(make_number, None, msg6, show_progress=False)
    demo.load(make_number, None, msg7, show_progress=False)
    demo.load(make_number, None, msg8, show_progress=False)
    demo.load(make_number, None, msg9, show_progress=False)
    demo.load(make_number, None, msg10, show_progress=False)
    demo.load(make_number, None, msg11, show_progress=False)
    demo.load(make_number, None, msg12, show_progress=False)
    demo.load(make_number, None, msg13, show_progress=False)
    demo.load(make_number, None, msg14, show_progress=False)
    demo.load(make_number, None, msg15, show_progress=False)
    demo.load(make_number, None, msg16, show_progress=False)
    demo.load(make_number, None, msg17, show_progress=False)
    demo.load(make_number, None, msg18, show_progress=False)
    demo.load(make_number, None, msg19, show_progress=False)
    demo.load(make_number, None, msg20, show_progress=False)
    demo.load(make_number, None, msg21, show_progress=False)
    demo.load(make_number, None, msg22, show_progress=False)
    demo.load(make_number, None, msg23, show_progress=False)
    demo.load(make_number, None, msg24, show_progress=False)

    msg1.change(lambda x: x, msg1, msg2)
    msg2.change(lambda x: x, msg2, msg3)
    msg3.change(lambda x: x, msg3, msg4)
    msg4.change(lambda x: x, msg4, msg5)
    msg5.change(lambda x: x, msg5, msg6)
    msg6.change(lambda x: x, msg6, msg7)
    msg7.change(lambda x: x, msg7, msg8)
    msg8.change(lambda x: x, msg8, msg9)
    msg9.change(lambda x: x, msg9, msg10)
    msg10.change(lambda x: x, msg10, msg11)
    msg11.change(lambda x: x, msg11, msg12)
    msg12.change(lambda x: x, msg12, msg13)
    msg13.change(lambda x: x, msg13, msg14)
    msg14.change(lambda x: x, msg14, msg15)
    msg15.change(lambda x: x, msg15, msg16)
    msg16.change(lambda x: x, msg16, msg17)
    msg17.change(lambda x: x, msg17, msg18)
    msg18.change(lambda x: x, msg18, msg19)
    msg19.change(lambda x: x, msg19, msg20)
    msg20.change(lambda x: x, msg20, msg21)
    msg21.change(lambda x: x, msg21, msg22)
    msg22.change(lambda x: x, msg22, msg23)
    msg23.change(lambda x: x, msg23, msg24)

demo.queue()
demo.launch(
    max_threads=64,
#    server_name='0.0.0.0',
#    share=True
#    ssl_verify=False,
#    ssl_keyfile='key.pem',
#    ssl_certfile='cert.pem'
)

The error happens almost every time I refresh the page with this updated script.

@abidlabs behold, I have obtained a reproduction after a lot of trial and error. Here it is:

import random
import time

import gradio as gr

def make_number():
    time.sleep(random.random() * 0.01)
    return str(random.randint(0, 8))

with gr.Blocks() as demo:
    with gr.Tab():
        msg1 = gr.Textbox()
        msg2 = gr.Textbox()
        msg3 = gr.Textbox()
        msg4 = gr.Textbox()

    with gr.Tab():
        msg5 = gr.Textbox()
        msg6 = gr.Textbox()
        msg7 = gr.Textbox()
        msg8 = gr.Textbox()

    demo.load(make_number, None, msg1, show_progress=False)
    demo.load(make_number, None, msg2, show_progress=False)
    demo.load(make_number, None, msg3, show_progress=False)
    demo.load(make_number, None, msg4, show_progress=False)
    demo.load(make_number, None, msg5, show_progress=False)
    demo.load(make_number, None, msg6, show_progress=False)
    demo.load(make_number, None, msg7, show_progress=False)
    demo.load(make_number, None, msg8, show_progress=False)

    msg1.change(lambda x: x, msg1, msg2)
    msg2.change(lambda x: x, msg2, msg3)
    msg3.change(lambda x: x, msg3, msg4)
    msg4.change(lambda x: x, msg4, msg5)
    msg5.change(lambda x: x, msg5, msg6)
    msg6.change(lambda x: x, msg6, msg7)
    msg7.change(lambda x: x, msg7, msg8)

demo.queue()
demo.launch(
    max_threads=64,
    server_name='0.0.0.0',
#    ssl_verify=False,
#    ssl_keyfile='key.pem',
#    ssl_certfile='cert.pem'
)

To reproduce:

  1. Launch the script above with python gradio-error.py
  2. Access the UI from another computer in the same local network
  3. If the error doesnā€™t happen on the first try, refresh the page. It may be necessary to refresh some 10 times before it happens.

This is the error:

error

I hope that helps identify what is going on so that I can finally update to Gradio 4 šŸ˜‚

@aliabid94 it seems to fix the issue for me šŸ˜ƒ

I have launched text-generation-webui some 50 times, and have also used the UI for a bit, and didnā€™t see any of the error popups, whereas they happened very consistently before. No errors in the terminal as well.

My simple reproduction code above also doesnā€™t generate errors anymore.

Well done!

Can you guys try the package from https://github.com/gradio-app/gradio/pull/7683 and see if it fixes your issues? To install:

pip install https://gradio-builds.s3.amazonaws.com/f64ab41e78ed2bd9838ae967ab9be9b4a40aeef7/gradio-4.21.0-py3-none-any.whl

Thanks @oobabooga ! I can repro on one machine with a share link so Iā€™ll use that to look into this. Much appreciated!! šŸ™