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

connection time out when websocket saved large image from backend #3591

Closed
iGoinbl opened this issue Aug 25, 2024 · 2 comments
Closed

connection time out when websocket saved large image from backend #3591

iGoinbl opened this issue Aug 25, 2024 · 2 comments
Labels
question Further information is requested

Comments

@iGoinbl
Copy link

iGoinbl commented Aug 25, 2024

Description

websocket connection time out :

i wanted to ask something about my app first of here it is a snapshot of it :
everything is working great now except for one thing i am connected to comfyui as a backend with websockets ok ? when the generated image is large 4k or larger it doesn't return anything and the app gets time out message and reloads the websockets connection says 1000 sometimes more ms i already optimised the upload with aiofiles i convert all the images to web p with max size 2048 pixels max for viewing into the ui i think this problem happens when the webscoket is saving the image from comfyui since it taking long the ui freezes it is not when the ui is trying to load the webp its when the image generation is done and its saving this problem is not happening with 2k images do you guys have any idea any help would be great
image

async def get_images(prompt):
    try:
        logging.info("Attempting WebSocket connection...")
        async with websockets.connect(
            f"ws://{server_address}/ws?clientId={client_id}", 
            max_size=1024 * 1024 * 100, 
            ping_interval=0.5, 
            ping_timeout=None,
            close_timeout=600  # 10 minutes timeout for closing the connection
        ) as ws:
            logging.info("WebSocket connection established.")

            async with aiohttp.ClientSession() as session:
                logging.info("Queueing prompt...")
                prompt_id = (await queue_prompt(session, prompt))['prompt_id']
                logging.info(f"Prompt ID: {prompt_id}")

                output_images = {}
           
                max_progress_steps = 20
                progress_step = 1 / max_progress_steps

                while True:
                    out = await ws.recv()
                    logging.info(f"Received WebSocket message: {out[:200]}")

                    if isinstance(out, str):
                        message = json.loads(out)
                        if message['type'] == 'executing':
                            data = message['data']
                            if data['node'] is None and data['prompt_id'] == prompt_id:
                                logging.info("Execution complete.")
                                break
                            
                    else:
                        logging.info("Received non-string message, likely binary data.")
                        continue

                history = (await get_history(session, prompt_id))[prompt_id]
                for node_id, node_output in history['outputs'].items():
                    if 'images' in node_output:
                        images_output = []
                        for image in node_output['images']:
                            logging.info(f"Fetching image: {image['filename']}")
                            image_data = await get_image(session, image['filename'], image['subfolder'], image['type'])
                            images_output.append(image_data)
                        output_images[node_id] = images_output

           
            logging.info("All images fetched successfully.")
            return output_images

    except websockets.exceptions.ConnectionClosed as e:
        logging.error(f"WebSocket connection closed unexpectedly: {e}")
        return None
    except Exception as e:
        logging.error(f"An error occurred: {e}")
        return None
@falkoschindler
Copy link
Contributor

It's hard to tell what your code is actually doing and when this function is called.
Why is it important to provide a minimal reproducible example?

@falkoschindler falkoschindler added the question Further information is requested label Aug 25, 2024
@rodja
Copy link
Member

rodja commented Aug 26, 2024

Is the image loaded via websocket? Maybe there is a max_buffer_size which block big data packages like we see in #3410.

@falkoschindler falkoschindler closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants