Comments (5)
Because when you call lua_pushstring
(to push e.g. payload
) when memory constrained, lua may longjmp
out due to memory allocation failure. libmosquitto does not handle such a thing safely (and is not documented to).
from lua-mosquitto.
Callback functions (on_connect, on_message, etc.) are called from non-lua code; which I cannot see as documented to be longjmp safe.
I had a look into the libmosquitto code base, and it's evident that longjmp
ing out is unsafe, as the cleanup code here: https://github.com/eclipse/mosquitto/blob/8025f5a29b78551e1d5e9ea13ae9dacabb6830da/lib/net_mosq.c#L1142-L1147 would get skipped (amoung other issues).
The issue in coming up with a fix is that libmosquitto doesn't provide any way to report errors from callbacks; and will immediately process the next packet.
I think this means that errors in a user's lua callback also have to be silent (as we have nowhere to report them to). Sending PR with this fix.
from lua-mosquitto.
ok, I'm of the opinion now, as I was back then, that user callbacks should not be pcalled, because, as you mention yourself, this means that errors in user code are silently discarded. See 57634bc
I strongly feel this is the domain of the user to handle properly.
from lua-mosquitto.
They must be pcalled, to do otherwise would break libmosquitto in a way that the only solution is to abort()
the process.
The open question is: what to do when pcall indicates an error: my current PR does nothing (throwing the error away). Instead you may want to get it back to the caller (though libmosquitto doesn't make it easy).
from lua-mosquitto.
how does this break:
function realhandler(mid, topic, payload, qos, retain)
blah
end
mqtt:set_callback(mosq.ON_MESSAGE, function(mid, topic, payload, qos, retain)
local ok, err = pcall(realhandler, mid, topic, payload, qos, retain)
end)
Because you want to do an awful lot of extra C code just to throw away errors. The code above makes it absolutely user choice how to handle the errors, and correctly does the pcall.
Alternatively, you could try and just reverting 57634bc and adding an api call that provides some sort of pcall handler for the case when it fails, but that sounds like a complicated user API for no gain.
from lua-mosquitto.
Related Issues (15)
- Lua 5.2 support HOT 2
- Create new version tag v0.2 HOT 6
- Add luarocks support HOT 2
- Callbacks occur in same coroutine that mqtt.new is called from HOT 6
- Callbacks are called from other threads HOT 4
- Segmentation fault(core dumped) when using mosquitto client as a thread along with lua lanes HOT 1
- mqtt5 support API design? HOT 1
- SEO; add mqtt to description HOT 4
- reconnect_async missing HOT 1
- create release tag HOT 1
- rockspec for Lua 5.3: LUA_COMPAT_APIINTCASTS HOT 5
- Usage of luaL_checkint HOT 2
- valgrind leak HOT 9
- cpu hog on teardown? pthread_join HOT 1
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 lua-mosquitto.