From 11d5fbd6321c9342972be30b7c631fad71093a95 Mon Sep 17 00:00:00 2001 From: Billal GHILAS Date: Wed, 28 Jan 2026 17:14:32 +0100 Subject: [PATCH] Handle send errors gracefully --- lib/ex_rtmp/server/client_session.ex | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ex_rtmp/server/client_session.ex b/lib/ex_rtmp/server/client_session.ex index 393ffbe..72bb2c2 100644 --- a/lib/ex_rtmp/server/client_session.ex +++ b/lib/ex_rtmp/server/client_session.ex @@ -116,14 +116,18 @@ defmodule ExRTMP.Server.ClientSession do @impl true def handle_cast({:video_data, timestamp, data}, state) do - send_media(:video, state.socket, state.stream_id, timestamp, data) - {:noreply, state} + case send_media(:video, state.socket, state.stream_id, timestamp, data) do + :ok -> {:noreply, state} + {:error, reason} -> {:stop, reason, state} + end end @impl true def handle_cast({:audio_data, timestamp, data}, state) do - send_media(:audio, state.socket, state.stream_id, timestamp, data) - {:noreply, state} + case send_media(:audio, state.socket, state.stream_id, timestamp, data) do + :ok -> {:noreply, state} + {:error, reason} -> {:stop, reason, state} + end end @impl true @@ -385,7 +389,7 @@ defmodule ExRTMP.Server.ClientSession do payload: data } - :ok = :gen_tcp.send(socket, Message.serialize(message, chunk_stream_id: chunk_stream_id)) + :gen_tcp.send(socket, Message.serialize(message, chunk_stream_id: chunk_stream_id)) end defp send_messages(state, []), do: state