mirror of
https://github.com/seriyps/mtproto_proxy.git
synced 2026-08-04 15:19:47 +00:00
Handle some of 'unknown_upstream' errors as expected race-condition
This commit is contained in:
parent
8026fb5552
commit
bf01459be5
1 changed files with 19 additions and 3 deletions
|
|
@ -129,7 +129,7 @@ handle_cast({proxy_ans, Down, Data}, #state{down = Down} = S) ->
|
|||
handle_cast({close_ext, Down}, #state{down = Down, sock = USock, transport = UTrans} = S) ->
|
||||
lager:debug("asked to close connection by downstream"),
|
||||
ok = UTrans:close(USock),
|
||||
{stop, normal, S};
|
||||
{stop, normal, S#state{down = undefined}};
|
||||
handle_cast({simple_ack, Down, Confirm}, #state{down = Down} = S) ->
|
||||
lager:info("Simple ack: ~p, ~p", [Down, Confirm]),
|
||||
{noreply, S};
|
||||
|
|
@ -289,8 +289,24 @@ up_send(Packet, #state{stage = tunnel,
|
|||
|
||||
down_send(Packet, #state{down = Down} = S) ->
|
||||
%% lager:debug(">Down: ~p", [Packet]),
|
||||
ok = mtp_down_conn:send(Down, Packet),
|
||||
{ok, S}.
|
||||
case mtp_down_conn:send(Down, Packet) of
|
||||
ok ->
|
||||
{ok, S};
|
||||
{error, unknown_upstream} ->
|
||||
handle_unknown_upstream(S)
|
||||
end.
|
||||
|
||||
handle_unknown_upstream(#state{down = Down, sock = USock, transport = UTrans} = S) ->
|
||||
%% there might be a race-condition between packets from upstream socket and
|
||||
%% downstream's 'close_ext' message. Most likely because of slow up_send
|
||||
ok = UTrans:close(USock),
|
||||
receive
|
||||
{'$gen_cast', {close_ext, Down}} ->
|
||||
lager:debug("asked to close connection by downstream"),
|
||||
throw({stop, normal, S#state{down = undefined}})
|
||||
after 0 ->
|
||||
throw({stop, got_unknown_upstream, S})
|
||||
end.
|
||||
|
||||
|
||||
%% Internal
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue