Fix MatchError crash when TURN socket closes during allocation refresh#91
Fix MatchError crash when TURN socket closes during allocation refresh#91georgeday-firefly wants to merge 4 commits intoelixir-webrtc:masterfrom
Conversation
Handle {:error, :closed} when transport_module.send fails during
TURN allocation refresh. Previously caused MatchError crashes that
terminated WebRTC streams.
Changes:
- Wrap transport_module.send calls in case statements
- Gracefully close transactions/candidates on socket errors
- Add debug logging for troubleshooting
Fixes crashes at lines 947 and 976 when TURN sockets close unexpectedly.
| update_gathering_state(ice_agent) | ||
| end | ||
|
|
||
| {nil, %{client: %{state: :error}}} -> |
There was a problem hiding this comment.
Added a guard in handle_ex_turn_msg to skip relay candidates whose TURN client is already in :error state, preventing a FunctionClauseError in ExTURN.Client.handle_message/2 when stale Process.send_after timer messages (allocation refresh, permission refresh) are delivered after the client has errored out during teardown.
There was a problem hiding this comment.
I'd opt to add the missing function clause in ex_turn instead. Could you verify the patch from elixir-webrtc/ex_turn#9 works correctly?
| update_gathering_state(ice_agent) | ||
| end | ||
|
|
||
| {nil, %{client: %{state: :error}}} -> |
There was a problem hiding this comment.
I'd opt to add the missing function clause in ex_turn instead. Could you verify the patch from elixir-webrtc/ex_turn#9 works correctly?
|
Hi there sure I can try it out - will report back |
Fixes crash:
When TURN sockets close unexpectedly during allocation refresh,
transport_module.send/3returns{:error, :closed}, causing the above MatchError that terminates WebRTC streams.This PR wraps the send calls in case statements to handle errors gracefully by closing the transaction/candidate and cleaning up state.