New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rescue ENOTCONN #2367
Rescue ENOTCONN #2367
Conversation
I looked into this earlier, wondering about adding at test for it. Everything I tried raised a Also, wondered whether it would be better to replace the following method in def peeraddr(swallow: false)
@socket.peeraddr
end with something like: def peeraddr(swallow: false)
@socket.peeraddr
rescue => e
if swallow
["<unknown>"]
else
raise e
end
end I think it's used four times, three times inside Thanks for the PR. EDIT: Re the test, I was working with net/http, later on I'll try a raw ssl socket. Re the We could remove the 'swallow' logic and make it alwasy trap errors, code needing the errors could just use ssl_skt.to_io.peeraddr -or- |
@MSP-Greg Good point, base on current use of |
I noticed that in Lines 495 to 501 in 18f1810
Hence, maybe change Lines 269 to 279 in 18f1810
to: def peerip
@peerip ||= if @remote_addr_header
(@env[@remote_addr_header] || LOCALHOST_IP).split(/[\s,]/).first
else
@io.to_io.peeraddr.last
end
end Other than cleaning up/shortening the logic, the real change is ping @nateberkopec... |
So, a regular TCPSocket will raise a SocketError as well if it can't get the peer:
So, from my perspective, MiniSSL sockets should have the same contract. That means we should fix this not in the MiniSSL object, but at the location of the callers. Or at least I'm reluctant to. There's three callsites for peeraddr in Puma rn: Client, Reactor, and Server. Each is doing something slightly different. I think putting a new abstraction in here would be kind of tough. But we need to think about what happens at each location if peeraddr raises an exception. |
Sorry, I should have given a fuller explanation. In Server & Reactor, the call to In Client, it's only used in Server also contains code to set Also, re Events, So, I think this is an improvement, but I'm not sure if |
For the Lines 188 to 196 in 18f1810
puma/ext/puma_http11/mini_ssl.c Lines 427 to 464 in 18f1810
I have zero knowledge with c, but looks like it will return |
Thanks. I guess I kind of forgot that many client ssl connections are made without a cert. I'm sure the code is ok. |
@MSP-Greg for the swallow error part, I personally preference maintain the same interface rather than a handy abstraction. Rescue the error in the caller might be a more suitable choice, what do you think? |
I don't have strong feelings about how this is fixed. But, some thoughts:
Given the above, I still prefer to catch in Regardless, I'll defer to @nateberkopec. I'm an old guy that has strong opinions, but moving forward is more important. Lines 211 to 218 in 18f1810
|
@MSP-Greg How about the previous idea you metioned? def peeraddr(swallow: false)
@socket.peeraddr
rescue => e
if swallow
["<unknown>"]
else
raise e
end
end The default behavior of |
Agreed. |
I really screwed up. I'll fix asap. In #2368, I forgot that I split some attr_* statements to show version info. Dumb, dumb, dumb... |
LGTM. Hate to ask, can you rebase? |
f0a1c6e
to
1c4a33a
Compare
@MSP-Greg Sure. It's a great experience, thanks you and @nateberkopec to review my PR. 😺 |
Description
Rescue
Errno::ENOTCONN
since it doesn't have socket addressCloses: #2335
Your checklist for this pull request
[changelog skip]
or[ci skip]
to the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.