diff options
author | Philipp Hörist <philipp@hoerist.com> | 2023-01-17 16:05:08 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2023-01-17 16:05:44 +0300 |
commit | 3e4fee240f88cf7fed7648ea8cd9181daf919359 (patch) | |
tree | 82e6e8044fbfa2e1ae9b362d7b56ecbd4f4cbd7d | |
parent | 50c8c1cdabf920fb2f52728928bf1fd81c82b533 (diff) |
fix: Handle race condition when cancelling request
Fixes #136
-rw-r--r-- | nbxmpp/http.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/nbxmpp/http.py b/nbxmpp/http.py index 9265a5d..ba19d84 100644 --- a/nbxmpp/http.py +++ b/nbxmpp/http.py @@ -449,6 +449,17 @@ class HTTPRequest(GObject.GObject): self._set_failed(HTTPRequestError.STATUS_NOT_OK) return + self._log.info('Request status: %s', Soup.Status.get_phrase(status)) + + if self._cancellable.is_cancelled(): + # It can happen that the message is finished before the + # response callback returns after calling cancel(). If + # we call complete, the response callback will also + # try to cleanup and will fail. + self._log.info('Skip setting message complete because ' + 'cancel is in progess') + return + self._set_complete() def _set_failed(self, error: HTTPRequestError) -> None: |