zauberzeug / nicegui

Create web-based user interfaces with Python. The nice way.
https://nicegui.io
MIT License
10.11k stars 606 forks source link

Getting ConnectionResetError in Error logs when using port 443 along with SSL certificates #3961

Open trivedihoney opened 1 week ago

trivedihoney commented 1 week ago

Description

I'm currently using port 443 and SSL certificates in ui.run to run the niceGUI server. And it works. Site becomes accessible using the domain name. However, I have a logger, initialized and the logger is logging multiple errors as shown below while browsing website pages.

2024-11-07 21:34:16,981 ERROR Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(None)>
Traceback (most recent call last):
  File "C:\Users\HT\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\HT\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 165, in _call_connection_lost
    self._sock.shutdown(socket.SHUT_RDWR)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

I tried a minimal code as below and still faced the same issue. I am not sure why this error is occurring.

from nicegui import ui, app, run
import config as c
import logging
logging.basicConfig(filename='error.log', level=logging.ERROR, format='%(asctime)s %(levelname)s %(message)s')
app.storage.clear()

@ui.page('/')
def index():
    app.storage.user['count'] = app.storage.user.get('count', 0) + 1
    with ui.row():
        ui.label('your own page visits:')
        ui.label().bind_text_from(app.storage.user, 'count')

ui.run(
    port=443,
    storage_secret='testsecret2',
    reload=False,
    show=False,
    ssl_certfile=c.SSL_CERTFILE, #cert.pem
    ssl_keyfile=c.SSL_KEYFILE, #key.pem
)
rodja commented 4 days ago

We can not reproduce the behaviour: After accepting a self-signed certificate the page shows without logging errors.

Are there any errors in the js console of the browser? Does it also happen without NiceGUI (eg. pure FastAPI & Uvicorn):

#!/usr/bin/env python3
import uvicorn
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse

app = FastAPI()

@app.get("/", response_class=PlainTextResponse)
def index():
    return "Hello, World!"

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=443, ssl_certfile="cert.pem", ssl_keyfile="key.pem")