Comments (6)
Hi @alexsporn, thanks for your comprehensive reply :) My apologies for not replying to this earlier, I have been very busy lately...
I absolutely agree with all of the issues you've highlighted here, and have been trying to think about the best way to handle this and ensure we don't create any unintended consequences.
I plan to look into it more thoroughly between now and the weekend if I get some time, but tentatively I think the correct (even expected) behaviour would be to drop the packet if the QOS is 0 and the client buffer is fully, otherwise to add it to the inflight queue. This should apply to both inline-message publishing by the embedding service, and also when a client publishes to the broker and the message is delegated out to subscribing clients.
A brief reminder of the code suggests that writing to clients is blocking (in as much as we wait to write to the client's buffer if it's full). This makes me suspect that a client publishing to a topic with many subscribers could theoretically block until all clients are iterated, which is not ideal. I will have a think about how we might alleviate this bottleneck.
from server.
Hi @alexsporn! This is very interesting - the possibility never occurred to me.
Currently I am inclined to think the best solution is the one you have described:
- If the buffer is full, then writing the message should fail with the error message to the embedding platform.
- The QOS of the inline-publisher is always 2 (exactly once), so we don't have to modify how this is handled.
- If the QOS of the receiving client subscription is 1/2, then the message should be added to the client's inflight messages queue.
Perhaps we should also make the buffer size for inline publish an value in server.Options. @alexsporn what's your use case which triggered this?
In the meantime I have increased the buffer to 4096 in v1.3.2 👍🏻
from server.
Hi @mochi-co , thanks for looking in to the issue.
We are using MQTT over WebSocket as a Pub/Sub mechanism to listen to messages processed by our node software.
We faced some issues on one of the nodes running the MQTT broker which has a JavaScript-client (QoS 0) always connected and receives all unfiltered messages (between 50-300 a second). Due to this client slowing down the broker and blocking the Publish()
function from enqueueing any more messages, the node started to slow down itself and not process any more messages.
Initially I thought it could be an issue in how we handle the incoming messages and publish them, so I went on to reproduce the bug. Using a JavaScript client (https://github.com/mqttjs/MQTT.js), publishing about 2000 packets a second and forcing the client to sleep between incoming messages to simulate slow processing of each packet, I could reproduce the MQTT broker lockup. Normally I'd say this would be no issue, but this can be used as a Denial-Of-Service attack on public brokers.
With the proposed change, the slow QoS 0 client will not influence any other connected clients and slow down the broker. As soon as the slow client clears up enough buffer it will start receiving messages again.
If the slow client is using QoS 1/2 this opens up another "attack vector" to the broker. If a long InflightTTL
is used (defaults to 24 hours), then you can force the memory usage of the broker to quickly go up by using a couple of slow clients. All pending packets will stay in the inflight messages queue.
I totally understand that QoS 1/2 give certain guarantees on how MQTT behaves, but a slow client should not influence the brokers performance. Maybe we need a max count of inflight messages per client?
What do you think?
from server.
@alexsporn I merged your recent PR, can you try pulling down master and seeing it the problem still exists? :) Thank you!
from server.
@alexsporn I've reverted #97 and reopened this issue as the solution for #97 causes the broker to stall (as per #101) under heavy load. I believe this may be related to the broker dropping acks if the queue is full rather than waiting.
from server.
This issue has been resolved in v2.0.0
from server.
Related Issues (20)
- Logging Level is not Configurable Via File Configuration
- Persistence storage did not work with SetCleanSession(false) HOT 3
- Don't allow inheriting session unless username matches HOT 5
- MessageExpiry Hook HOT 4
- OnConnectAuthenticate cannot specify an error code (like Client Identifier not valid)
- Resend timeout inflight messages
- Bug in inflight message restore from datastore HOT 2
- Proposal: Add an Example for Custom Hook Usage HOT 2
- can I use mqtts ? HOT 2
- OCSP Stapling support ? HOT 1
- Metrics HOT 4
- MQTT bridge HOT 3
- Is it possible to dynamically remove a hook likewise we add them? HOT 2
- Client supplied ID is used to look up existing clients in inheritSession, while the store of existing actually uses the server assigned if one exists. HOT 8
- Got error when enable compression of websocket listener HOT 1
- Dynamic Removal of the Hooks HOT 1
- Clients MQTT often experience disconnection listener=tcp1 error=EOF and i/o timeout HOT 1
- How to configure WSS HOT 3
- Function attachClient sometimes does not call Done() on ClientsWg. HOT 4
- Potential race condition when using Ledger.Update 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 server.