1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Handle ENOTCONN client disconnects when setting REMOTE_ADDR

This commit is contained in:
Jacob Shafton 2015-07-02 10:29:26 -05:00
parent e1eb3ecbe8
commit cd7a9d91f9
2 changed files with 9 additions and 2 deletions

View file

@ -111,6 +111,7 @@ module Puma
PORT_80 = "80".freeze
PORT_443 = "443".freeze
LOCALHOST = "localhost".freeze
LOCALHOST_IP = "127.0.0.1".freeze
SERVER_PROTOCOL = "SERVER_PROTOCOL".freeze
HTTP_11 = "HTTP/1.1".freeze

View file

@ -457,10 +457,16 @@ module Puma
#
unless env.key?(REMOTE_ADDR)
addr = client.peeraddr.last
begin
addr = client.peeraddr.last
rescue Errno::ENOTCONN
# Client disconnects can result in an inability to get the
# peeraddr from the socket; default to localhost.
addr = LOCALHOST_IP
end
# Set unix socket addrs to localhost
addr = "127.0.0.1" if addr.empty?
addr = LOCALHOST_IP if addr.empty?
env[REMOTE_ADDR] = addr
end