Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
45e30be6 by Philipp Hörist at 2023-03-18T18:03:28+01:00
fix: HTTP: Make sure streams are closed only once

Stream.close() can have side effects which lead to the method
beeing called twice in the same Mainloop iteration.

- - - - -


1 changed file:

- nbxmpp/http.py


Changes:

=====================================
nbxmpp/http.py
=====================================
@@ -483,13 +483,24 @@ class HTTPRequest(GObject.GObject):
         self._cleanup()
 
     def _close_all_streams(self) -> None:
-        if self._input_stream is not None:
-            if not self._input_stream.is_closed():
-                self._input_stream.close(None)
+        # stream.close() will invoke signals on the Message object
+        # which in turn can lead to this method called again in the
+        # same Mainloop iteration. This means is_closed() will not
+        # return True and we get an GLib.IOError.PENDING error.
 
-        if self._output_stream is not None:
-            if not self._output_stream.is_closed():
-                self._output_stream.close(None)
+        input_stream = self._input_stream
+        output_stream = self._output_stream
+
+        self._input_stream = None
+        self._output_stream = None
+
+        if input_stream is not None:
+            if not input_stream.is_closed():
+                input_stream.close(None)
+
+        if output_stream is not None:
+            if not output_stream.is_closed():
+                output_stream.close(None)
 
     def _cleanup(self) -> None:
         self._log.info('Run cleanup')
@@ -501,9 +512,6 @@ class HTTPRequest(GObject.GObject):
         del self._session
         del self._user_data
 
-        self._input_stream = None
-        self._output_stream = None
-
         if self._timeout_id is not None:
             GLib.source_remove(self._timeout_id)
             self._timeout_id = None



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/45e30be68e80fa21d870d56a49cb1d75ef698f3c

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/45e30be68e80fa21d870d56a49cb1d75ef698f3c
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to