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

Commits:

1 changed file:

Changes:

  • nbxmpp/http.py
    ... ... @@ -483,13 +483,24 @@ class HTTPRequest(GObject.GObject):
    483 483
             self._cleanup()
    
    484 484
     
    
    485 485
         def _close_all_streams(self) -> None:
    
    486
    -        if self._input_stream is not None:
    
    487
    -            if not self._input_stream.is_closed():
    
    488
    -                self._input_stream.close(None)
    
    486
    +        # stream.close() will invoke signals on the Message object
    
    487
    +        # which in turn can lead to this method called again in the
    
    488
    +        # same Mainloop iteration. This means is_closed() will not
    
    489
    +        # return True and we get an GLib.IOError.PENDING error.
    
    489 490
     
    
    490
    -        if self._output_stream is not None:
    
    491
    -            if not self._output_stream.is_closed():
    
    492
    -                self._output_stream.close(None)
    
    491
    +        input_stream = self._input_stream
    
    492
    +        output_stream = self._output_stream
    
    493
    +
    
    494
    +        self._input_stream = None
    
    495
    +        self._output_stream = None
    
    496
    +
    
    497
    +        if input_stream is not None:
    
    498
    +            if not input_stream.is_closed():
    
    499
    +                input_stream.close(None)
    
    500
    +
    
    501
    +        if output_stream is not None:
    
    502
    +            if not output_stream.is_closed():
    
    503
    +                output_stream.close(None)
    
    493 504
     
    
    494 505
         def _cleanup(self) -> None:
    
    495 506
             self._log.info('Run cleanup')
    
    ... ... @@ -501,9 +512,6 @@ class HTTPRequest(GObject.GObject):
    501 512
             del self._session
    
    502 513
             del self._user_data
    
    503 514
     
    
    504
    -        self._input_stream = None
    
    505
    -        self._output_stream = None
    
    506
    -
    
    507 515
             if self._timeout_id is not None:
    
    508 516
                 GLib.source_remove(self._timeout_id)
    
    509 517
                 self._timeout_id = None