IMD SolutionComputing LibraryShop main store

Troubleshooting

Why an MQTT client reconnects but then publishes nothing

Edge computing and IIoT Published 7 min read

Short answer

A connected status and a clean return from the publish call prove only that the library accepted the message, not that the broker received it. Confirm every publish with the client's own PUBLISH log entry and the broker-side PUBACK, and treat a reconnect followed by silence as a stalled client: restart the MQTT client, or reboot the gateway when no separate restart exists.

On this page
  1. What a connected status actually proves
  2. The failure signature to capture
  3. Why the stall follows a reconnect
  4. Working a reconnect stall on a 30-second keep-alive, QoS 1 client
  5. Recovering a stalled client
  6. Set an acceptance test the stall cannot pass
  7. Questions asked

When an MQTT client reconnects, reports itself connected, and then accepts your publish calls without a single exception, it is tempting to declare the data flowing again. That is not proof. The reported failure pattern is consistent: after a brief WAN or cellular drop the client reconnects, keep-alive traffic resumes, the status check passes, but the client never emits its PUBLISH log entry and no data arrives at the broker. The stall does not clear by waiting. Treat a connected status and a clean return from the publish call as unproven, verify every publish with the client's PUBLISH log entry and the broker's PUBACK, and recover by restarting the MQTT client — or rebooting the gateway when the client cannot be restarted on its own.

What a connected status actually proves #

The status check reports session state, not message flow. In the reported applications the gate was a call like getStatus, returning 5 as its connected value, evaluated before every publish. Keep-alive PINGREQ and PINGRESP pairs continued straight through the failures, so the session was genuinely alive and the broker saw a healthy, idle client. The publish call returning without an exception proves only that the library accepted the message. None of those three signals touches the transmit path, which is how a client can pass all three and still send nothing.

Treat the status gate as necessary but not sufficient, and never let a green indicator end the investigation. The same overtrust exists on the monitoring side, where MQTT Engine shows online status after an edge node drops — an online reading that outlives the connection it describes.

The failure signature to capture #

Log these five observations at every reconnect; the first three together are the diagnosis.

  • The status check returns the connected value — 5 in the reported clients — immediately before a publish that comes back without an exception.
  • No sending PUBLISH entry appears under the client's MQTT log source. The client logs that line for every message it transmits, so its absence means the message never entered the network.
  • No PUBACK returns for the message. At QoS 1 the sender holds a copy of every PUBLISH until the broker's PUBACK releases it, so a missing PUBACK means the broker never confirmed receipt.
  • PINGREQ and PINGRESP exchanges continue on schedule, so the session is alive while the publish path is dead.
  • The broker's presence log shows the disconnect and the reconnect, but no application data after it.

When the sending PUBLISH entry is present but the PUBACK never arrives, the fault sits beyond the client — investigate the broker and the network path instead of restarting the client. The two cases look alike at the status check and must not be confused.

Why the stall follows a reconnect #

Every captured occurrence followed a brief loss of upstream connectivity. Two of the three affected devices were on cellular — one on a poor 3G network, one on a good 4G one — and the third sat on a reliable Ethernet line; all three stalled, so no link type is immune, and the cellular units failed most often. Note that the clients detected the drop and reconnected successfully: disconnect detection worked, and what stayed broken was the publish path after the reconnect. In the reported incidents the stall persisted until the MQTT client was restarted or the device rebooted, and it never recovered on its own.

The same troubleshooting window contained a firmware upgrade and a switch to QoS 1 publishing, so the evidence does not isolate a single root cause; treat the client's internal state after reconnection as the working hypothesis and re-prove the publish path after every reconnect. The fault is also distinct from one where an edge gateway's MQTT stops sending after a reboot, which begins with the gateway rebooting rather than a connectivity drop. A messy reconnect can corrupt data even when messages flow again; the neighboring case is a historian that stores zero after an MQTT edge node reconnects.

Working a reconnect stall on a 30-second keep-alive, QoS 1 client #

The inputs, with their sources:

  • Keep-alive: 30 seconds — the connection settings reported for the affected clients.
  • Publish QoS: 1 — the configuration in effect during the failures.
  • Broker connection: TLS on port 8883 — the reported endpoint.
  • Trigger: one momentary upstream drop, then a reconnect — the start of every reported capture.

The rule, from the MQTT specification's keep-alive requirement: a broker must close a connection from which it has received no packet for 1.5 times the keep-alive period, and any packet, including PINGREQ, resets that timer.

The arithmetic: broker-side disconnect window 1.5 × 30 s = 45 s. Observation window for this example: three keep-alive periods, 3 × 30 s = 90 s.

The result: the stalled client defeats the 45 s rule because it is not silent — its PINGREQ and the broker's PINGRESP keep resetting the timer, so the broker never declares the connection dead and the session can sit open indefinitely while the publish log stays empty. Across 90 s of normal publish attempts there is no sending PUBLISH entry and no PUBACK. That combination is a stalled client, not a slow broker.

The decision: restart the MQTT client at that point; if no separate restart exists, reboot the gateway. After either action, require the sending PUBLISH entry and the matching PUBACK before calling the link recovered. For any other client, scale the observation window to three keep-alive periods of its own setting.

Recovering a stalled client #

  1. Confirm at the broker that its presence log shows the same disconnect and reconnect you saw on the client, so both sides refer to one event.
  2. Attempt publishes at the normal cadence and record each call's return. Expect a clean return, and expect it to prove nothing beyond acceptance.
  3. Read the client's MQTT log source for the sending PUBLISH entry after the reconnect.
  4. Apply the observation window from the example: three keep-alive periods, which is 90 s at the reported 30-second setting.
  5. No sending PUBLISH entry and no PUBACK inside the window means a stalled client: restart the MQTT client. If it cannot be restarted on its own, or the stall returns, reboot the gateway in a window when briefly losing the gateway's other traffic is acceptable.
  6. After recovery, verify the full path: connected status, one sending PUBLISH entry per message, one PUBACK per message, and the data visible at the broker. Keep-alive traffic alone is not an acceptance test.
  7. If the stall survives restarts and a reboot, capture the evidence before touching anything else: device backup and support files, firmware identifier, transport type, connection parameters, interruption timestamps, the client's MQTT logs, the broker's presence events, and the last successful and first failed publish attempts. A restart destroys the stalled session state, and the vendor can only investigate what you preserve — submit it through the vendor's own support channel.

Set an acceptance test the stall cannot pass #

Define the pass condition as four checks made after every reconnect: connected status, one sending PUBLISH entry per published message, one PUBACK per message, and the data visible at the broker. A client that passed before the drop has not passed after it — a reconnect voids the previous verdict. QoS 1 is what makes the test strong, because its two-packet handshake gives you an acknowledgement to require; QoS 0 gives you none.

Reverting the publish QoS and shortening the keep-alive were both proposed during the reported incidents, and neither has a documented before-and-after result. Treat both as isolation experiments: change one, log the sending PUBLISH entries and the broker receipts, and judge only from that comparison. A shorter keep-alive makes a genuinely dead link surface sooner, which helps disconnect detection; it does nothing to a client that holds a live session while refusing to publish.

Confirm too what the broker accepts: some brokers cap the QoS they honor, and what happens to a higher setting — a downgrade or a refusal — depends on the broker and protocol version, which walkthrough on resolving QoS 2 downgrades on QoS 1-only brokers covers in detail. The keep-alive mechanism creates the same traps outside MQTT: keep-alive reconnect handling on FINS/TCP is the parallel case of stale sessions surviving behind healthy-looking links.

The decision, case by case:

  • sending PUBLISH entry and PUBACK present after every reconnect: healthy; no action.
  • Clean publish returns with no sending PUBLISH entry across three keep-alive periods: stalled client; restart the MQTT client.
  • No separate restart available, or the stall returns: reboot the gateway.
  • The stall survives a reboot: escalate with the evidence pack, and isolate the most recent change in the publishing stack — firmware or QoS configuration — one change at a time, logging both records after each.

Questions asked

What happens to messages accepted by the publish call during a stall?

At QoS 1 the client holds a copy of every message until PUBACK releases it, so messages accepted while the publish path is stalled pile up unsent. When a restart revives the path, expect that backlog to flush as a burst, and design the consumer for QoS 1's at-least-once delivery, which permits duplicates. Confirm the burst on the broker before resuming normal operation.

Can I detect the stall without access to the gateway's logs?

Yes, from the receiving side. If the broker's presence log shows the reconnect while no application messages arrive and the client's keep-alive exchange continues, the publish path is stalled. A separate subscribing test client on a wildcard topic gives the same verdict from anywhere, and it doubles as the receiver for your acceptance test after recovery.

Does dropping from QoS 1 to QoS 0 avoid the stall?

No result was documented for that change in the reported incidents. Mechanically it removes the acknowledgement, so a stalled QoS 0 client leaves no missing PUBACK to detect and the same fault becomes harder to see rather than fixed. If you try it, treat it as an isolation experiment: log the PUBLISH entries and broker receipts before and after, and judge only from that comparison.

How do I prove delivery at QoS 0 or QoS 2?

QoS 0 has no acknowledgement, so the only proof is receipt at the broker or your test subscriber; build the test around the receiving end. QoS 2 uses a four-part handshake per message, so a compliant client emits more packets than the QoS 1 pair. Verify the full exchange your client actually logs before writing the acceptance test.

Keep reading

  • Troubleshooting

    Fix MQTT sensor data missing in Node-RED

    A green MQTT connection in Node-RED proves only a broker session, not that the GSM module published a value or that the flow subscribes to its topic. An http in node cannot receive MQTT publications at all: use an mqtt in node. Trace RS-485 acquisition, publish result, broker identity and topic match in order, and fix the first stage with no positive result.

    Edge computing and IIoT

  • Troubleshooting

    Historian stores zero after an MQTT edge node reconnects

    A 0 stored just before the true value at every MQTT edge reconnect is a reported pattern on Ignition 8.1.5 through 8.1.15 with the MQTT Transmission and Engine modules 4.0.6 through 4.0.10. Confirm it by querying stored records around each reconnect, exclude those zeros from process data, and remove them with a timestamped rule instead of a blanket zero filter.

    Edge computing and IIoT

  • Troubleshooting

    MQTT TLS connects but no CONNACK: find the failing hop

    The connect callback fires only when the broker returns a CONNACK, so with TCP ESTABLISHED and no callback the failure is in the TLS handshake or between TLS and MQTT. Run openssl s_client against the listener, then mosquitto_sub -d with the same CA file and credentials; wrong credentials are not the cause, because the broker answers those with a CONNACK that fires the callback with a return code.

    Edge computing and IIoT