Comments (7)
Hello!
I just run into that issue too. It's due to a fact that Exception here is in fact MQTT::Exception
instead of ::Exception
and I wonder if this is intentionally implemented that way? Because of that, if the connection is broken for some reason the thread dies silently and the only trace of that is in the logs.
I don't want to globally set abort_on_exception
, but if using MQTT::Exception
is intentional, maybe allowing one to set this value for the @read_thread
specifically via some config option + having the issue described somewhere would be enough?
My fix for now is something like this:
MQTT::Client.prepend(Module.new do
def receive_packet
super
rescue ::Exception => ex
Thread.current[:parent].raise(ex)
end
end)
from ruby-mqtt.
I don't think this fixes the issue were talking about here. If I find some time, I'll create a PR to include a proposed solution in the gems code.
from ruby-mqtt.
@JakubSzajna but ruby-mqtt has this definition: mqtt.rb#L23
module MQTT
...
# Super-class for other MQTT related exceptions
class Exception < ::Exception
end
...
end
Used here: mqtt/client.rb#L476
# Pass exceptions up to parent thread
rescue Exception => exp
unless @socket.nil?
@socket.close
@socket = nil
handle_close
end
Thread.current[:parent].raise(exp)
end
Is @socket.close
and handle_close
considered in your fix? How can I catch the exception in my case, described in the first comment of this issue?
from ruby-mqtt.
@phlegx Yes, it does have this definition and it branches out from stdlib Exception
.
rescue Exception => exp
in MQTT
module refers to MQTT::Exception
instead of ::Exception
though.
So it would catch exceptions like MQTT::Exception
and everything that inherits from MQTT::Exception
.
Errno::ECONNRESET
does not have MQTT::Exception
in it's ancestors chain, so it won't be catched in the rescue clause you mentioned.
The monkey-patch from my message wraps the whole receive_packet
in the rescue clause, so every exception that will be raised inside receive_packet
will be catched there and elevated to the parent thread. Hope this is the answer for your question :) It is supposed to make sure the exception from your initial message (and others from inside the receive_packet
method) can be rescued. So this does not actually rescue from the exception, it just makes it rescue
'able :) To catch this exception, use a rescue clause in a scope where you use MQTT::Client.connect
method.
from ruby-mqtt.
@JakubSzajna can you write a PR please?
from ruby-mqtt.
Found similar PR #112 related to StandardError.
from ruby-mqtt.
I don't think this fixes the issue were talking about here. If I find some time, I'll create a PR to include a proposed solution in the gems code.
any hope for this PR?
from ruby-mqtt.
Related Issues (20)
- Unable to authenticate HOT 16
- Websocket support HOT 5
- Error OpenSSL alert unknown ca HOT 1
- MQTT client on weak CPU and high traffic environment
- background client
- SSL connection failing due to optimisations in PR #134 HOT 6
- I have renamed the 'master' branch to 'main'
- Drop support for ruby 1.9 HOT 2
- unable to establish QoS1 sessions
- Release plan HOT 14
- Error: can't modify frozen OpenSSL::SSL::SSLContext HOT 1
- How to handle sigterm? HOT 2
- supporting private keys other than RSA
- Need help? HOT 1
- Remove autoload HOT 1
- Is using a connection Pool Recommended?
- Major issue while using Thread to catch exception
- ruby-mqtt-271ee631f128/lib/mqtt/packet.rb:223:in `read_byte': Failed to read byte from socket (MQTT::ProtocolException) HOT 2
- Support for MQTT 5 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-mqtt.