Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mtproto_proxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mtproto_proxy
Commits
d1bc6d90
Unverified
Commit
d1bc6d90
authored
Aug 29, 2019
by
Sergey Prokhorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respawn failed downstream connections. Fixes gh-25
parent
46800f06
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
6 deletions
+26
-6
mtp_dc_pool.erl
src/mtp_dc_pool.erl
+24
-4
mtp_down_conn.erl
src/mtp_down_conn.erl
+2
-2
No files found.
src/mtp_dc_pool.erl
View file @
d1bc6d90
...
...
@@ -33,6 +33,7 @@
-
define
(
SERVER
,
?
MODULE
).
-
define
(
APP
,
mtproto_proxy
).
-
define
(
BURST_MAX
,
10
).
-
define
(
DEFAULT_INIT_CONNS
,
4
).
-
type
upstream
()
::
mtp_handler
:
handle
().
-
type
downstream
()
::
mtp_down_conn
:
handle
().
...
...
@@ -92,7 +93,7 @@ status(Pool) ->
%%% gen_server callbacks
%%%===================================================================
init
(
DcId
)
->
InitConnections
=
application
:
get_env
(
mtproto_proxy
,
init_dc_connections
,
4
),
InitConnections
=
application
:
get_env
(
?
APP
,
init_dc_connections
,
?
DEFAULT_INIT_CONNS
),
State
=
#state
{
dc_id
=
DcId
,
downstreams
=
ds_new
([])},
State1
=
connect_many
(
InitConnections
,
State
),
...
...
@@ -184,15 +185,34 @@ handle_down(MonRef, Pid, Reason, #state{downstreams = Ds,
Pending1
=
lists
:
delete
(
Pid
,
Pending
),
Ds1
=
ds_remove
(
Pid
,
Ds
),
?
log
(
error
,
"Downstream=
~p
is down. reason=
~p
"
,
[
Pid
,
Reason
]),
maybe_restart_connection
(
St
#state
{
pending_downstreams
=
Pending1
,
downstreams
=
Ds1
,
downstream_monitors
=
DsM1
}
;
downstream_monitors
=
DsM1
})
;
_
->
?
log
(
error
,
"Unexpected DOWN. ref=
~p
, pid=
~p
, reason=
~p
"
,
[
MonRef
,
Pid
,
Reason
]),
St
end
end
.
maybe_restart_connection
(
#state
{
pending_downstreams
=
[],
downstream_monitors
=
DsM
}
=
St
)
->
MinConnections
=
application
:
get_env
(
?
APP
,
init_dc_connections
,
?
DEFAULT_INIT_CONNS
),
OpenConnections
=
map_size
(
DsM
),
case
OpenConnections
<
MinConnections
of
true
->
%% We have less than minimum connections. Just spawn new one
connect
(
St
);
false
->
%% We have more than minimum connections.
%% Don't spawn anything, because it will be done on-demand
St
end
;
maybe_restart_connection
(
St
)
->
%% We already have pending connections. Just wait for them to complete
St
.
maybe_spawn_connection
(
CurrentMin
,
#state
{
pending_downstreams
=
Pending
}
=
St
)
->
%% if N > X and len(pending) < Y -> connect()
%% TODO: shrinking (by timer)
...
...
src/mtp_down_conn.erl
View file @
d1bc6d90
...
...
@@ -168,8 +168,8 @@ handle_info(do_connect, #state{dc_id = DcId} = State) ->
{
ok
,
St1
}
=
connect
(
DcId
,
State
),
{
noreply
,
St1
}
catch
?
WITH_STACKTRACE
(
Class
,
Reason
,
Stack
)
?
log
(
error
,
"Down connect error:
~s
"
,
[
lager
:
pr_stacktrace
(
Stack
,
{
Class
,
Reason
})]),
%XXX lager-specific
?
log
(
error
,
"Down connect
to dc=
~w
error:
~s
"
,
[
DcId
,
lager
:
pr_stacktrace
(
Stack
,
{
Class
,
Reason
})]),
%XXX lager-specific
erlang
:
send_after
(
300
,
self
(),
do_connect
),
{
noreply
,
State
}
end
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment