fix(ws): do not panic in EspWebSocketClient::drop on destroy failure - #657
Open
SAY-5 wants to merge 1 commit into
Open
fix(ws): do not panic in EspWebSocketClient::drop on destroy failure#657SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
esp-rs#648 fixed the unwrap on esp_websocket_client_close inside Drop, but left the matching call to esp_websocket_client_destroy as esp!(unsafe { esp_websocket_client_destroy(self.handle) }).unwrap(); A Drop impl must not panic. On ESP-IDF targets built with panic = "abort" any panic in Drop aborts the whole application without unwinding. The failure is reachable in practice: new_raw constructs the client before calling esp_websocket_client_start(), so a failed start returns Err and drops a client whose transport was never established, which can make the destroy call fail. Apply the same treatment as the close call: log the error and swallow it. Fixes esp-rs#653 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
SAY-5
force-pushed
the
fix/ws-drop-destroy-no-panic
branch
from
May 31, 2026 02:42
6901c11 to
95be340
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
#648 fixed the
unwrap()onesp_websocket_client_closeinsideEspWebSocketClient::drop, but left the matching call toesp_websocket_client_destroyas:A
Dropimpl must not panic. On ESP-IDF targets built withpanic = "abort"any panic inDropaborts the whole applicationwithout unwinding, so this is worse than a missed error.
The failure is reachable in practice:
new_rawconstructs the clientbefore calling
esp_websocket_client_start(), so a failed start returnsErrvia?and drops a client whose transport was never established,which is exactly the scenario where
destroycan fail. Reported in#653.
Fix
Apply the same treatment already used for
close: log the error andswallow it. Same warning style so log noise stays consistent.
Fixes #653