Skip to content

Commit

Permalink
Fix case where acceptors shut down forever after max_connections is hit
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Dec 27, 2023
1 parent 7e102ee commit ab93507
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/thousand_island/acceptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule ThousandIsland.Acceptor do
else
{:error, :too_many_connections} ->
ThousandIsland.Telemetry.span_event(span, :spawn_error)
accept(listener_socket, connection_sup_pid, server_config, span, count + 1)

{:error, reason} when reason in [:closed, :einval, :econnaborted] ->
ThousandIsland.Telemetry.stop_span(span, %{connections: count})
Expand Down
14 changes: 14 additions & 0 deletions test/thousand_island/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ defmodule ThousandIsland.ServerTest do
assert :gen_tcp.recv(client, 0) == {:ok, ~c"HELLO"}
assert :gen_tcp.recv(other_client, 0) == {:error, :closed}
:gen_tcp.close(other_client)

# Close the first connection and ensure new connections are now accepted
:gen_tcp.close(client)

# Give things enough time for the first connection to time out
Process.sleep(500)

{:ok, third_client} = :gen_tcp.connect(:localhost, port, active: false)
:ok = :gen_tcp.send(third_client, "BUONGIORNO")

# Give things enough time to send if they were going to
Process.sleep(100)

assert :gen_tcp.recv(third_client, 0) == {:ok, ~c"BUONGIORNO"}
end

test "should emit telemetry events as expected" do
Expand Down

0 comments on commit ab93507

Please sign in to comment.