hypercorn icon indicating copy to clipboard operation
hypercorn copied to clipboard

SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY

Open pgjones opened this issue 3 years ago • 2 comments

This seems to be a bug with asyncio... I have done some searching on this issue and it seems like an old bug that should be fixed. I have not made many changes to my quart app, but this problem is suddenly happening. When this error occurs the backend closes requests from the frontend until new requests are made.

Some information that may be useful is... the screens of my frontend which are creating this error in the backend are sending multiple async api calls to quart at the same time... I have disabled all requests except 1 request per screen and the backend stopped closing requests and the frontend stopped hanging. I do not really have a need for async backend currently, so considering going to Flask if this is an async issue with the backend, but wanted to report this bug to the dev team here at quart.

Traceback:

Task exception was never retrieved future: <Task finished name='Task-2685' coro=<worker_serve.._server_callback() done, defined at /usr/local/lib/python3.10/site-packages/hypercorn/asyncio/run.py:94> exception=SSLError(1, '[SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY] application data after close notify (_ssl.c:2672)')> Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 70, in run await self._read_data() File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 107, in _read_data await self.protocol.handle(RawData(data)) File "/usr/local/lib/python3.10/site-packages/hypercorn/protocol/init.py", line 62, in handle return await self.protocol.handle(event) File "/usr/local/lib/python3.10/site-packages/hypercorn/protocol/h2.py", line 188, in handle await self._handle_events(events) File "/usr/local/lib/python3.10/site-packages/hypercorn/protocol/h2.py", line 255, in _handle_events await self.streams[event.stream_id].handle(EndBody(stream_id=event.stream_id)) KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 56, in run async with TaskGroup(self.loop) as task_group: File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 75, in aexit await task asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/run.py", line 96, in _server_callback await TCPServer(app, loop, config, context, reader, writer) File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 74, in run await self._close() File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 117, in _close await self.writer.wait_closed() File "/usr/local/lib/python3.10/asyncio/streams.py", line 344, in wait_closed await self._protocol._get_close_waiter(self) File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received ssldata, appdata = self._sslpipe.feed_ssldata(data) File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 206, in feed_ssldata self._sslobj.unwrap() File "/usr/local/lib/python3.10/ssl.py", line 979, in unwrap return self._sslobj.shutdown() ssl.SSLError: [SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY] application data after close notify (_ssl.c:2672) [2022-08-29 20:58:07 +0000] [1] [INFO] 99.7.90.52:57862 GET /users/users 2 200 353 3331 Task exception was never retrieved future: <Task finished name='Task-2696' coro=<worker_serve.._server_callback() done, defined at /usr/local/lib/python3.10/site-packages/hypercorn/asyncio/run.py:94> exception=SSLError(1, '[SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY] application data after close notify (_ssl.c:2672)')> Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 70, in run await self._read_data() File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 107, in _read_data await self.protocol.handle(RawData(data)) File "/usr/local/lib/python3.10/site-packages/hypercorn/protocol/init.py", line 62, in handle return await self.protocol.handle(event) File "/usr/local/lib/python3.10/site-packages/hypercorn/protocol/h2.py", line 188, in handle await self._handle_events(events) File "/usr/local/lib/python3.10/site-packages/hypercorn/protocol/h2.py", line 255, in _handle_events await self.streams[event.stream_id].handle(EndBody(stream_id=event.stream_id)) KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 56, in run async with TaskGroup(self.loop) as task_group: File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 75, in aexit await task asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/run.py", line 96, in _server_callback await TCPServer(app, loop, config, context, reader, writer) File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 74, in run await self._close() File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/tcp_server.py", line 117, in _close await self.writer.wait_closed() File "/usr/local/lib/python3.10/asyncio/streams.py", line 344, in wait_closed await self._protocol._get_close_waiter(self) File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received ssldata, appdata = self._sslpipe.feed_ssldata(data) File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 206, in feed_ssldata self._sslobj.unwrap() File "/usr/local/lib/python3.10/ssl.py", line 979, in unwrap return self._sslobj.shutdown() ssl.SSLError: [SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY] application data after close notify (_ssl.c:2672)

requirements.txt

quart==0.18.0 APScheduler==3.8.1 Quart-CORS==0.5.0 paho-mqtt==1.6.1 flask-marshmallow==0.14.0 pexpect==4.8.0 marshmallow-sqlalchemy==0.26.1 requests==2.25.1 jsonschema==4.3.2 pymongo Jinja2==3.0.3 bcrypt pyjwt

Dockerfile

FROM python:3.10.6-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt

RUN apt-get update RUN apt-get -y install gcc RUN apt-get install -y awscli sshpass netcat-openbsd wget build-essential libffi-dev python-dev

RUN pip3 install -r requirements.txt

COPY . .

COPY etc/hosts /etc/beta_app/ COPY deployments /etc/beta_app

CMD ["python3", "app.py"]

Environment:

  • Python version: Tested on 3.8-slim-buster, 3.9-slim-buster, and 3.10.6-slim-buster (docker images)
  • Quart version: 0.18.0

pgjones avatar Aug 30 '22 20:08 pgjones

Any update here?

I also have this issue with my FastAPI app over https.

ibot3 avatar Apr 30 '23 16:04 ibot3

Having the same issue. Looking at that file, is it possible to just add SSLError to the errors being handled on this line?

https://github.com/pgjones/hypercorn/blob/d7990fb4b07a9b87390f60dcb1647789f99cdcc6/src/hypercorn/asyncio/tcp_server.py#L118

I'm not exceptionally experienced with SSL, but my guess is that some sort of request is being passed to/from the application, to a socket which is already closed, so we can just assume that the connection has been closed at the point where this error happens?

UpstreamData avatar Sep 26 '23 15:09 UpstreamData

I think this is fixed, please open a new issue if not

pgjones avatar Jun 03 '24 20:06 pgjones

The error has not been fixed. On version 0.17.3 the exact same error occurs.

Kamp11 avatar Jul 03 '24 12:07 Kamp11