-
Notifications
You must be signed in to change notification settings - Fork 111
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
when I disable broker, client which use set_pingresp_timeout(2s) would block in force_disconnect() for more than 30 minutes. #976
Comments
Thank you for reporting the issue. Let me confirm your situation.
Thanks to your analysis, I understand the root issue quickly. mqtt_cpp/include/mqtt/tcp_endpoint.hpp Lines 169 to 177 in 6e624ae
The member function
Unfortunalely, as far as I've checked, there is no way to set timeout to If I would look over some timeout option setter functionality, please let me know. I guess that Boost.Asio doesn't provide timeout parameter to sync function such as mqtt_cpp has async version of shutdown mechanism. It works well with timeout. mqtt_cpp/include/mqtt/tcp_endpoint.hpp Lines 178 to 192 in 6e624ae
Your code uses sync version. So if you want to use timeout use async APIs instead of sync APIs. e.g. call async_connect() instead of connect(). NOTE: connect() APIs also doesn't have timeout. You might think that even if users use sync APIs, the shutdown part should be async version to support timeout. I recommend using async APIs like async_connect(). By the way, could you re-form your post? It's difficult to see (code part and text part). |
thank you for such a quick reply. so the following is my solution in my app. Can you give me some advices?
(4) if mqtt_client doesn't receive the pingresp for 30s(it's timeout.), call I found that only |
force_shutdown_and_close is defined as follows: mqtt_cpp/include/mqtt/tcp_endpoint.hpp Lines 109 to 112 in 6e624ae
lowest_layer() is https://www.boost.org/doc/libs/1_82_0/doc/html/boost_asio/reference/ip__tcp/socket.html The bottom of the page, you can see the following description: Thread Safety Shared objects: Unsafe. Synchronous send, receive, connect, and shutdown operations are thread safe with respect to each other, if the underlying operating system calls are also thread safe. This means Distinct Object means socket1, socket2. Theread safe is obious as long as they are not shareing static member. So, if you think your environment, calling Instead of calling force_shutdown_and_close(), you can get c->socket()->lowest_layer() (ip::tcp::socket), and call only shutdown(). Perhaps it would unblock the ssl::stream::shutdown. |
thank you for you advice. by the way, I changed my demo from sync mode to async mode, and run it. but the result is same as the old version. here is my code of async mode demo._
here is the backtrace.
and I check the code of mqtt_cpp about set_pingresp_timer.
I found that whatever user use sync mode or async mode, it only call the sync api force_disconnect() in here. I think if I use the async mode , it should call the async api async_force_disconnect. |
so this is the reason why it still call sync api "shutdown" even I use the async mode. |
Please try #977 for your async version example. |
thank you, I have tested using the code of branch #977. it runs good for my demo. it quick close the connection after pingresp timeout. |
Thank you for testing. I merged #977. It solves async version of pingresp timeout issue. NOTE: |
Hello, I want to talk with your about some quetions
after called ioc.run(), the thread will block in here. the thread could not released except io_context released.
thank you. |
Yes, I agreed. It is very important not only ioc.run() correclty finish but also avoiding unexpected finish. If there is no events in ioc queue, then ioc.run() would return unexpectedly. In order to avoid it you can use work_guard.
When mqtt_cpp call asio's async_read internallty, but no packet is received. In this case ioc ins never be released. Now, you are interented in how to finish ioc.run() well. In order to timeout, you can set timer s.g. steady_timer by yourself.
mqtt_cpp doesn't have serious problem. I just published my new library named https://github.com/redboltz/async_mqtt What is the difference between mqtt_cpp and async_mqtt ?
The following parts are about async part of mqtt_cpp.
async_mqtt solves these problems. |
Hello, I have replaced mqtt lib by the latest version and change the mode from sync to async. |
Hello,
I have a issue as follow.
I have called set_pingresp_timeout(20s) in my mqtt client. I think if I pause the broker(or unplug network cable), mqtt client would call force_disconnect() and then on_error callback is called. but actually mqtt client block in force_disconnect() for more than 30 minutes.
following is the code for reproducing this issue.
Following is the backtrace in GDB after I pause the broker.
I read the code of boost according to above backtrace.(the version of boost is boost_1_78_0). I found mqtt client is blocked at boost/asio/detail/impl/socket_ops.ipp:894.
because I have paused the broker , and the timeout is set to -1 to wait forever. so poll_read would never return.
The text was updated successfully, but these errors were encountered: