Skip to content

Reconnect behavior with WebSockets & SSL #38

@seiband

Description

@seiband

Hi all,

I've been running into an issue when trying to connect to a broker (mosquitto 2.0.19) using websockets & ssl.
The initial connection to the mqtt broker works fine and I can also observe logs on both client and broker.
If the connection drops (e.g. broker is shutdown), the client doesn't automatically reconnect to the broker and no further logs are visible.
All other combinations (tcp without ssl, tcp with ssl, websockets without ssl) are working as expected.

Reproduction steps

  1. Instantiate mqtt client with websocket & ssl
boost::beast::websocket::stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>
  1. Start client and call async_run
  2. Start MQTT broker with compatible configuration
  3. Wait for successful client connection
  4. Stop MQTT broker
  5. Completion handler of async_run is executed with error code operation_canceled
  6. Client doesn't try to reconnect

Expected behavior
The client reconnects automatically independent of the underlying transport layers and the completion handler of async_run is not called.
At least logs should be there to indicate errors in the underlying transport layers.

Actual behaviour
The client doesn't reconnect automatically after the first successful connection. In fact, the completion handler of async_run is called with error code operation_canceled.

Analysis
As mentioned in the introduction I've already tested various transport configurations and this issue only exists for websockets & ssl.
I've also debugged my application when the completion handler of async_run is fired.
The expression _svc_ptr->is_open() evaluates to false in one of the files (sentry_op.hpp) which leads to the execution of the completion handler.
Does the combination of websockets and ssl behave differently here?

Workaround
If I call async_run again from within the completion handler, I can get the client to start connecting to the broker again.
(whether that's a good or bad idea is probably another discussion...)

Best regards,
Stefan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions