forked from platypush/platypush
Catch response write errors in the MQTT callback.
If the client that forwarded the request is no longer available (either because an exception or a timeout was raised) then its I/O buffer and event loop may be closed. In this case, the response callback should handle and report the exception, and still set the event, so that any other threads waiting for the response can move on.
This commit is contained in:
parent
ca7f042ccc
commit
b76f141b61
1 changed files with 12 additions and 5 deletions
|
@ -479,8 +479,9 @@ class MqttPlugin(RunnablePlugin):
|
||||||
client.stop()
|
client.stop()
|
||||||
del client
|
del client
|
||||||
|
|
||||||
@staticmethod
|
def _response_callback(
|
||||||
def _response_callback(reply_topic: str, event: threading.Event, buffer: IO[bytes]):
|
self, reply_topic: str, event: threading.Event, buffer: IO[bytes]
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
A response callback that writes the response to an IOBuffer and stops
|
A response callback that writes the response to an IOBuffer and stops
|
||||||
the client loop.
|
the client loop.
|
||||||
|
@ -490,8 +491,14 @@ class MqttPlugin(RunnablePlugin):
|
||||||
if msg.topic != reply_topic:
|
if msg.topic != reply_topic:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
buffer.write(msg.payload)
|
buffer.write(msg.payload)
|
||||||
client.loop_stop()
|
client.loop_stop()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warning(
|
||||||
|
'Could not write the response back to the MQTT client: %s', e
|
||||||
|
)
|
||||||
|
finally:
|
||||||
event.set()
|
event.set()
|
||||||
|
|
||||||
return on_message
|
return on_message
|
||||||
|
|
Loading…
Reference in a new issue