25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Avoid late arrival of get_disco_item response

This commit is contained in:
Evgeny Khramtsov 2019-05-11 19:27:56 +03:00
parent 4b6f1195c6
commit 3d8711f708
2 changed files with 25 additions and 14 deletions

View File

@ -740,9 +740,13 @@ iq_disco_items(_ServerHost, _Host, _From, Lang, _MaxRoomsDiscoItems, _Node, _RSM
-spec get_room_disco_item({binary(), binary(), pid()}, -spec get_room_disco_item({binary(), binary(), pid()},
term()) -> {ok, disco_item()} | term()) -> {ok, disco_item()} |
{error, timeout | notfound}. {error, timeout | notfound}.
get_room_disco_item({Name, Host, Pid}, Query) -> get_room_disco_item({Name, Host, Pid},
{get_disco_item, Filter, JID, Lang}) ->
RoomJID = jid:make(Name, Host), RoomJID = jid:make(Name, Host),
try p1_fsm:sync_send_all_state_event(Pid, Query, 100) of Timeout = 100,
Time = erlang:monotonic_time(millisecond),
Query1 = {get_disco_item, Filter, JID, Lang, Time+Timeout},
try p1_fsm:sync_send_all_state_event(Pid, Query1, Timeout) of
{item, Desc} -> {item, Desc} ->
{ok, #disco_item{jid = RoomJID, name = Desc}}; {ok, #disco_item{jid = RoomJID, name = Desc}};
false -> false ->

View File

@ -512,7 +512,7 @@ handle_event({set_affiliations, Affiliations},
handle_event(_Event, StateName, StateData) -> handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}. {next_state, StateName, StateData}.
handle_sync_event({get_disco_item, Filter, JID, Lang}, _From, StateName, StateData) -> handle_sync_event({get_disco_item, Filter, JID, Lang, Time}, _From, StateName, StateData) ->
Len = maps:size(StateData#state.nicks), Len = maps:size(StateData#state.nicks),
Reply = case (Filter == all) or (Filter == Len) or ((Filter /= 0) and (Len /= 0)) of Reply = case (Filter == all) or (Filter == Len) or ((Filter /= 0) and (Len /= 0)) of
true -> true ->
@ -521,10 +521,17 @@ handle_sync_event({get_disco_item, Filter, JID, Lang}, _From, StateName, StateDa
false -> false ->
false false
end, end,
CurrentTime = erlang:monotonic_time(millisecond),
if CurrentTime < Time ->
{reply, Reply, StateName, StateData}; {reply, Reply, StateName, StateData};
%% This clause is only for backwards compatibility true ->
{next_state, StateName, StateData}
end;
%% These two clauses are only for backward compatibility with nodes running old code
handle_sync_event({get_disco_item, JID, Lang}, From, StateName, StateData) -> handle_sync_event({get_disco_item, JID, Lang}, From, StateName, StateData) ->
handle_sync_event({get_disco_item, any, JID, Lang}, From, StateName, StateData); handle_sync_event({get_disco_item, any, JID, Lang}, From, StateName, StateData);
handle_sync_event({get_disco_item, Filter, JID, Lang}, From, StateName, StateData) ->
handle_sync_event({get_disco_item, Filter, JID, Lang, infinity}, From, StateName, StateData);
handle_sync_event(get_config, _From, StateName, handle_sync_event(get_config, _From, StateName,
StateData) -> StateData) ->
{reply, {ok, StateData#state.config}, StateName, {reply, {ok, StateData#state.config}, StateName,