Skip to content

Commit

Permalink
Don't exit the acceptor process when handling an econnaborted error
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Dec 27, 2023
1 parent ab93507 commit 54d0476
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/thousand_island/acceptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ defmodule ThousandIsland.Acceptor do
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] ->
{:error, :econnaborted} ->
ThousandIsland.Telemetry.span_event(span, :econnaborted)
accept(listener_socket, connection_sup_pid, server_config, span, count + 1)

{:error, reason} when reason in [:closed, :einval] ->
ThousandIsland.Telemetry.stop_span(span, %{connections: count})

{:error, reason} ->
Expand Down
5 changes: 4 additions & 1 deletion lib/thousand_island/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ defmodule ThousandIsland.Logger do
"""
@spec attach_logger(log_level()) :: :ok | {:error, :already_exists}
def attach_logger(:error) do
events = [[:thousand_island, :acceptor, :spawn_error]]
events = [
[:thousand_island, :acceptor, :spawn_error],
[:thousand_island, :acceptor, :econnaborted]
]

:telemetry.attach_many("#{__MODULE__}.error", events, &__MODULE__.log_error/4, nil)
end
Expand Down
16 changes: 16 additions & 0 deletions lib/thousand_island/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ defmodule ThousandIsland.Telemetry do
* `telemetry_span_context`: A unique identifier for this span
* `[:thousand_island, :acceptor, :econnaborted]`
Thousand Island was unable to spawn a process to handle a connection since the remote end
closed before we could accept it. This usually occurs when it takes too long for your server
to start processing a connection; you may want to look at tuning OS-level TCP parameters or
adding more server capacity.
This event contains the following measurements:
* `monotonic_time`: The time of this event, in `:native` units
This event contains the following metadata:
* `telemetry_span_context`: A unique identifier for this span
## `[:thousand_island, :connection, *]`
Represents Thousand Island handling a specific client request
Expand Down Expand Up @@ -281,6 +296,7 @@ defmodule ThousandIsland.Telemetry do
@type event_name ::
:ready
| :spawn_error
| :econnaborted
| :recv_error
| :send_error
| :sendfile_error
Expand Down

0 comments on commit 54d0476

Please sign in to comment.