Skip to content

Commit 3fac7f3

Browse files
committed
Properly mark tls errors in xmpp_stream_in
We didn't mark some tls error properly, which caused crashes when we later tried to convert them to text.
1 parent eec76d8 commit 3fac7f3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/xmpp_stream_in.erl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ send_ws_ping(#{owner := Owner, socket := Sock,
213213
case xmpp_socket:send_ws_ping(Sock) of
214214
ok ->
215215
State;
216-
{error, Why} ->
217-
process_stream_end({socket, Why}, State)
216+
{error, _} = Err ->
217+
process_stream_end(convert_socket_error(Err), State)
218218
end;
219219
send_ws_ping(State) ->
220220
State.
@@ -449,11 +449,8 @@ handle_info({tcp, _, Data}, #{socket := Socket} = State) ->
449449
case xmpp_socket:recv(Socket, Data) of
450450
{ok, NewSocket} ->
451451
State#{socket => NewSocket};
452-
{error, Reason} when is_atom(Reason) ->
453-
process_stream_end({socket, Reason}, State);
454-
{error, Reason} ->
455-
%% TODO: make fast_tls return atoms
456-
process_stream_end({tls, Reason}, State)
452+
{error, _} = Err ->
453+
process_stream_end(convert_socket_error(Err), State)
457454
end);
458455
% Skip new tcp messages after socket get removed from state
459456
handle_info({tcp, _, _}, State) ->
@@ -544,6 +541,12 @@ noreply(#{stream_timeout := {MSecs, StartTime}} = State) ->
544541
is_disconnected(#{stream_state := StreamState}) ->
545542
StreamState == disconnected.
546543

544+
convert_socket_error({error, Reason}) when is_atom(Reason) ->
545+
{socket, Reason};
546+
convert_socket_error({error, Reason}) ->
547+
%% TODO: make fast_tls return atoms
548+
{tls, Reason}.
549+
547550
-spec process_invalid_xml(state(), fxml:xmlel(), term()) -> state().
548551
process_invalid_xml(#{lang := MyLang} = State, El, Reason) ->
549552
case xmpp:is_stanza(El) of
@@ -1579,7 +1582,7 @@ send_header(#{stream_id := StreamID,
15791582
stream_header_sent => true},
15801583
case socket_send(State1, StreamStart) of
15811584
ok -> State1;
1582-
{error, Why} -> process_stream_end({socket, Why}, State1)
1585+
{error, _} = Err -> process_stream_end(convert_socket_error(Err), State1)
15831586
end;
15841587
send_header(State, _) ->
15851588
State.

0 commit comments

Comments
 (0)