Skip to content

Commit

Permalink
Set upper bound on {active, N} settings
Browse files Browse the repository at this point in the history
On a particularly quick network with wide buffers, it appears we can
overflow the number and crash arbitrary connections.

A few thousands packets ought to be enough to still reach decent speeds
without killing the underlying stack.
  • Loading branch information
ferd committed Oct 24, 2024
1 parent f702dd9 commit 5459e61
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/revault/src/revault_tls.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-define(CLIENT(Name), {via, gproc, {n, l, {tls, client, Name}}}).
-define(BACKOFF_THRESHOLD, 500).
-define(MIN_ACTIVE, 8).
-define(MAX_ACTIVE, 4096).
-record(client, {name, dirs, peer, dir, auth, opts, sock,
recv = false, buf = revault_tls:buf_new(),
active=?MIN_ACTIVE, ctx = []}).
Expand Down
2 changes: 1 addition & 1 deletion apps/revault/src/revault_tls_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ handle_event(info, {pong, T}, connected, Data=#client{sock=Sock, active=Active})
Now = erlang:monotonic_time(millisecond),
NewActive = case Now - T > ?BACKOFF_THRESHOLD of
true -> max(Active div 2, ?MIN_ACTIVE);
false -> Active * 2
false -> min(Active * 2, ?MAX_ACTIVE)
end,
ssl:setopts(Sock, [{active, NewActive}]),
{keep_state, Data#client{active=NewActive}, []};
Expand Down
2 changes: 1 addition & 1 deletion apps/revault/src/revault_tls_serv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ worker_loop(Dir, C=#conn{localname=Name, sock=Sock, buf=Buf0, active=Active}) ->
Now = erlang:monotonic_time(millisecond),
NewActive = case Now - T > ?BACKOFF_THRESHOLD of
true -> max(Active div 2, ?MIN_ACTIVE);
false -> Active * 2
false -> min(Active * 2, ?MAX_ACTIVE)
end,
ssl:setopts(Sock, [{active, NewActive}]),
worker_loop(Dir, C#conn{active=NewActive});
Expand Down

0 comments on commit 5459e61

Please sign in to comment.