From c9bb0eca29c1afb95c62682342f2e30a1d7bf189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2023 17:34:31 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20connections=20being=20clos?= =?UTF-8?q?ed=20too=20early?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turned UploadStorageFallbackHandler async for this as well. --- src/octoprint/server/__init__.py | 4 +++- src/octoprint/server/util/tornado.py | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index b290ede03..0f8928f5c 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -1026,7 +1026,9 @@ class Server: { "fallback": util.tornado.WsgiInputContainer( app.wsgi_app, - executor=ThreadPoolExecutor(), + executor=ThreadPoolExecutor( + thread_name_prefix="WsgiRequestHandler" + ), headers=headers, removed_headers=removed_headers, ), diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index 96136983a..3ab3bf621 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -564,7 +564,7 @@ class UploadStorageFallbackHandler(RequestlessExceptionLoggingMixin, CorsSupport self._new_body += value + b"\r\n" self._new_body += b"--%s--\r\n" % self._multipart_boundary - def _handle_method(self, *args, **kwargs): + async def _handle_method(self, *args, **kwargs): """ Takes care of defining the new request body if necessary and forwarding the current request and changed body to the ``fallback``. @@ -588,11 +588,11 @@ class UploadStorageFallbackHandler(RequestlessExceptionLoggingMixin, CorsSupport try: # call the configured fallback with request and body to use - future = self._fallback(self.request, body) - if future is not None and isinstance(future, tornado.concurrent.Future): - future.add_done_callback(self._cleanup_files) - self._headers_written = True - except Exception: + result = self._fallback(self.request, body) + if result is not None: + await result + # self._headers_written = True + finally: # make sure the temporary files are removed again self._cleanup_files()