fix(websocket): Fix close function with auto-reconnect-on-close #999
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
If auto-reconnect-on-close is configured, close should not try to stop the client, but just close the current connection.
This is needed to support fault injection for reliability testing of protocols like SocketIO, who will perform a higher-level connection-state-recovery.
This is also needed to support load balanced services, where a SocketIO event might indicate the client should temporarily disconnect to reconnect to a healthier or longer-living backend server.
Related
I introduced this bug in 19891d8, though it only broke for anyone trying to cleanly close a connection without stopping the client with this particular configuration.
Testing
Tested by adding a button to my UI that calls
esp_websocket_client_close_with_code(), and verifying I could manually close the websocket client and device automatically reconnects on demand.Checklist
Before submitting a Pull Request, please ensure the following:
Note
Ensures
esp_websocket_client_close_with_optional_body()does not stop the client whenauto_reconnectandclose_reconnectare enabled, allowing a clean close of the current connection and seamless auto-reconnect.CLOSE_FRAME_SENT_BIT, return early ifconfig->auto_reconnect && config->close_reconnect, skipping STOP/WAIT logicWritten by Cursor Bugbot for commit 2083a0b. This will update automatically on new commits. Configure here.