Skip to content

Commit

Permalink
handle bandit's get peer data exception
Browse files Browse the repository at this point in the history
As of bandit v1.5.7 during client disconnection it will raise "Unable to obtain transport_info: [reason]"
everytime it tries to get the transport info. This commit tries to handle that exception by returning nil
instead of bubbling the exception.
  • Loading branch information
ardhitama committed Oct 23, 2024
1 parent d6798d5 commit 5eb18de
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/sentry/plug_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,18 @@ defmodule Sentry.PlugContext do

defp remote_port(conn) do
case Plug.Conn.get_req_header(conn, "x-forwarded-for") do
[] -> nil
[_value | _rest] -> Plug.Conn.get_peer_data(conn).port
[] ->
nil

[_value | _rest] ->
# As of bandit v1.5.7 during client disconnection it will raise "Unable to obtain transport_info: [reason]"
# everytime it tries to get the transport info. Let's handle that exception by returning nil instead of bubbling the exception.
# Refer to: https://github.com/mtrudel/bandit/blob/b06e43dcee93c5c044b18ed8347838fc2a1728f0/lib/bandit/transport_info.ex#L26
try do
Plug.Conn.get_peer_data(conn).port
rescue
_ -> nil
end
end
end

Expand Down

0 comments on commit 5eb18de

Please sign in to comment.