Skip to content

fix(mqtt): shutdown sockets on relay teardown to ensure dropped clients are closed - #263

Open
boomesh11 wants to merge 1 commit into
Python-roborock:mainfrom
boomesh11:fix-relay-shutdown-endpoints
Open

boomesh11 wants to merge 1 commit into
Python-roborock:mainfrom
boomesh11:fix-relay-shutdown-endpoints

Conversation

@boomesh11

Copy link
Copy Markdown

Summary

When a client or Mosquitto drops a connection (e.g. Client has exceeded timeout, disconnecting), calling close() on both sockets in _relay() or _close_conn_endpoints() does not interrupt a concurrent blocking
ecv(4096) in the other relay thread on POSIX/Linux systems. This prevents the proxy from cleanly tearing down the connection, sending a FIN/RST packet, and logging [conn N] closed.

Adding endpoint.shutdown(socket.SHUT_RDWR) before endpoint.close() immediately interrupts any blocked
ecv() calls and delivers TCP FIN/RST to both the vacuum/client and the backend broker, allowing the relay threads to join cleanly and the connection to be deregistered.

Changes

  1. Call endpoint.shutdown(socket.SHUT_RDWR) in _relay finally block, _close_conn_endpoints, and _handle_client connection failure cleanup.
  2. Update fake sockets in ests/test_mqtt_tls_proxy.py and verify shutdown(socket.SHUT_RDWR) is called upon relay termination and endpoint closure.

Resolves #262

…ts are closed

When a client or the backend broker drops a connection or disconnects, calling close() without shutdown(SHUT_RDWR) leaves the peer relay thread blocked in recv() on Linux/POSIX sockets, preventing the connection from closing cleanly and evicting dropped clients.

Calling endpoint.shutdown(socket.SHUT_RDWR) unblocks blocking peer recvs and sends TCP FIN/RST immediately.

Fixes Python-roborock#262
@Lash-L Lash-L added area: mqtt MQTT broker, bridge, credentials and connection lifecycle. bug Something isn't working labels Nov 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mqtt MQTT broker, bridge, credentials and connection lifecycle. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MQTT TLS proxy (8881) stops answering handshakes; dropped clients not torn down; S7 Max Ultra evicted by keepalive

2 participants