Skip to content

Commit 957125f

Browse files
committed
Do not crash when connection is closed
Stream rebalancing can lead to many replica connections getting closed. With active streams, that caused replica readers to crash as they were performing `inet:setopts/2` / `ssl:setopts/2` on a closed connection.
1 parent 2d8a242 commit 957125f

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/osiris_log.erl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,18 +1505,21 @@ send_file(Sock,
15051505
true ->
15061506
%% this avoids any data sent in the Callback to be dispatched
15071507
%% in it's own TCP frame
1508-
ok = setopts(Transport, Sock, [{nopush, true}]),
1509-
_ = Callback(Header, ToSend),
1510-
case sendfile(Transport, Fd, Sock, Pos, ToSend) of
1508+
case setopts(Transport, Sock, [{nopush, true}]) of
15111509
ok ->
1512-
ok = setopts(Transport, Sock, [{nopush, false}]),
1513-
{ok, _} = file:position(Fd, NextFilePos),
1514-
{ok, State};
1515-
Err ->
1516-
%% reset the position to the start of the current
1517-
%% chunk so that subsequent reads won't error
1518-
{ok, _} = file:position(Fd, Pos),
1519-
Err
1510+
_ = Callback(Header, ToSend),
1511+
case sendfile(Transport, Fd, Sock, Pos, ToSend) of
1512+
ok ->
1513+
ok = setopts(Transport, Sock, [{nopush, false}]),
1514+
{ok, _} = file:position(Fd, NextFilePos),
1515+
{ok, State};
1516+
Err ->
1517+
%% reset the position to the start of the current
1518+
%% chunk so that subsequent reads won't error
1519+
{ok, _} = file:position(Fd, Pos),
1520+
Err
1521+
end;
1522+
Err -> Err
15201523
end;
15211524
false ->
15221525
{ok, _} = file:position(Fd, NextFilePos),
@@ -2189,9 +2192,9 @@ max_segment_size_reached(
21892192
CurrentSizeChunks >= MaxSizeChunks.
21902193

21912194
setopts(tcp, Sock, Opts) ->
2192-
ok = inet:setopts(Sock, Opts);
2195+
inet:setopts(Sock, Opts);
21932196
setopts(ssl, Sock, Opts) ->
2194-
ok = ssl:setopts(Sock, Opts).
2197+
ssl:setopts(Sock, Opts).
21952198

21962199
sendfile(_Transport, _Fd, _Sock, _Pos, 0) ->
21972200
ok;

0 commit comments

Comments
 (0)