-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disconnect on Publish when using WebSocket #1690
Comments
Maybe this is related, it sounds like a similar issue (but should be resolved in the latest build that I am using, 4.1.4.563): |
Some trace logging, maybe it helps:
|
I have tested a Publish to test.mosquitto.org:8080, also using WebSockets and it works just fine. So there is something different when connecting to my AWS endpoint. I also did a test using MQTTnet 3.1.2 and my AWS endpoint which also works fine. I tested a few MQTTnet 4.x versions and they all fail. What could be different since 4.x when Publishing to AWS? |
That's odd. If it works with 3.x then I would expect it to work with 4.x also. The trace shows a "Subscribe" just before a "Publish"; does it disconnect on "Publish" without any "Subscribe" also? BTW, have you tried #1691 with version 3.x also? |
Without the subscribe, the connection still closes. I also tried adding a few random delays (5 to 30 seconds) to make sure it is the publish that causes this. The only publish that doesn't cause the connection to close is a publish with an empty payload.
Yes, same result. So at least that is consistent (and expected since the root cause is a .Net Framework bug). |
I'll try to have a look during the week. Maybe this is related to #1689. |
It looks like there is some incompatibility between the AWS WebSocket server and the .NET ClientWebSocket that is used in MQTTnet. I'm not sure where this incompatibility lies but I could publish continuously without disconnection by using the WebSocket4Net extension:
Does that work for you? |
Yes, that does work indeed. Sounds like a reasonable workaround! |
The problem seems to be that the AWS WebSocket does not handle message fragments. I think compatibility here can be supported in MQTTnet by providing a WebSocket option |
Thanks @logicaloud , appreciate it. I'll leave it open for now. |
Here is the implementation of a client web socket option to use unfragmented messages: https://github.com/logicaloud/MQTTnet/tree/websocket-unfragmented-messages-option To use this option, you would need to set the option to
The effect is that messages are preassembled into a single buffer before hand-over to the underlying WebSocket. @stefxx, does that work for you? @chkr1011, I have considered implementing a fragment buffer in the |
Yes, excellent! This does fix the problem. Thank you very much! |
@logicaloud Thanks for pointing to the right direction with solving this issue with AWS. I added a branch to this PR and implemented a new option for the client. It will only change the internal memory management so that it will also apply for TCP connections (if ever needed there) and is not stateful. Please check the code and let me know what you think. |
Looks good to me (without paying too much attention to other refactoring). Having the client adapter factory handle the new option is better than extending the channel interface, and I don't see any harm in moving the One suggestion would be to avoid Amazon specific naming in the |
@logicaloud That is a good hint. I will update accordingly and remove the Amazon naming stuff. Could you please test the new commit as well? I have no access to an AWS broker... |
There seems to be a bug in the
|
Oh that was a stupid one 😄 |
Thanks again. I've just tested .WithoutPacketFragmentation with the 4.2 release and works perfectly! |
Describe the bug
After successfully connecting to AWS using WebSockets, and being able to receive messages, the connection is immediatly disconnected on a PublishAsync except when sending a empty payload.
Which component is your bug related to?
To Reproduce
Connect to AWS using WebSockets
Publish anything (except empty payload)
This is the code I use to Publish:
Note that the MqttClientDisconnectedEventArgs.Exception is nothing. Also, the PublishAsync.Result is "Success" and does not trigger an exception.
Expected behavior
That the Payload is being send without disconnecting from the broker
Thanks!
The text was updated successfully, but these errors were encountered: