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

Warn about communication attempts with disconnected clients #3123

Merged
merged 4 commits into from
May 27, 2024

Conversation

falkoschindler
Copy link
Contributor

This PR tries to solve issue #3028 where a memory leak in the application code only becomes apparent when trying to delete a UI element. To warn the user about a deleted client that is still in use, this PR checks the client whenever a message is enqueued in the outbox.

I tested with the following demo:

import asyncio
import time
from nicegui import app, ui

handlers = []

async def loop():
    while True:
        for handler in handlers:
            handler()
        await asyncio.sleep(1)

app.on_startup(loop)

@ui.page('/')
def page():
    log = ui.log(max_lines=10)
    handlers.append(lambda: log.push(f'Hello at {time.time()}'))

When closing a client and waiting a few seconds, a warning appears that a deleted client is used. Without this PR, we need to wait until elements are deleted from the overflowing log element, which causes a KeyError.

@falkoschindler falkoschindler marked this pull request as draft May 24, 2024 22:45
@falkoschindler falkoschindler added this to the 1.4.26 milestone May 24, 2024
@falkoschindler falkoschindler linked an issue May 24, 2024 that may be closed by this pull request
@falkoschindler falkoschindler added the enhancement New feature or request label May 24, 2024
This reverts commit bf089c2.
nicegui/client.py Outdated Show resolved Hide resolved
@falkoschindler falkoschindler marked this pull request as ready for review May 27, 2024 08:37
@rodja rodja merged commit bdc3a14 into main May 27, 2024
6 checks passed
@rodja rodja deleted the disconnected-client branch May 27, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError in ui.log after client disconnected
2 participants