Skip to content

Commit

Permalink
Wait until the stream is closed by the server on user removal
Browse files Browse the repository at this point in the history
When removing a user over XMPP, the server sends a stream error with
the "User removed" message, and closes the stream afterwards.
Wait until it happens to avoid having incoming messages in the queue
that would cause the wpool process to crash when trying to handle them later.
  • Loading branch information
chrzaszcz committed Jan 9, 2023
1 parent 8069263 commit e841f59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/escalus_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
get_tls_last_message/1,
reset_parser/1,
is_connected/1,
wait_for_close/1,
wait_for_close/2,
kill/1,
use_zlib/1,
Expand Down Expand Up @@ -424,6 +425,9 @@ upgrade_to_tls(#client{module = Mod, rcv_pid = Pid, props = Props}) ->
SSLOpts = proplists:get_value(ssl_opts, Props, []),
Mod:upgrade_to_tls(Pid, SSLOpts).

wait_for_close(Client) ->
wait_for_close(Client, default_timeout()).

%% @doc Waits at most MaxWait ms for the client to be closed.
%% Returns true if the client was disconnected, otherwise false.
-spec wait_for_close(client(), non_neg_integer()) -> boolean().
Expand Down
12 changes: 11 additions & 1 deletion src/escalus_users.erl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,17 @@ delete_user(Config, {_Name, UserSpec}) ->
{ok, Conn, _} = escalus_connection:start(Options),
escalus_connection:send(Conn, escalus_stanza:remove_account()),
Result = wait_for_result(Conn),
escalus_connection:stop(Conn),
try
{ok, result, _} = Result,
StreamError = escalus_connection:get_stanza(Conn, stream_error),
escalus:assert(is_stream_error, [<<"conflict">>, <<"User removed">>], StreamError),
StreamEnd = escalus_connection:get_stanza(Conn, stream_end),
escalus:assert(is_stream_end, StreamEnd),
escalus_connection:wait_for_close(Conn)
catch C:R:S ->
error_logger:error_msg("error when trying to delete user: ~p:~p, stacktrace: ~p~n", [C, R, S]),
escalus_connection:stop(Conn)
end,
Result.

-spec auth_type([proplists:property()]) -> {module, atom(), list()} | xmpp.
Expand Down

0 comments on commit e841f59

Please sign in to comment.