-
Notifications
You must be signed in to change notification settings - Fork 263
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
shutdown instead of close. #759
Conversation
@kazu-yamamoto Can you post how It'd be very interested to learn how that works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend adding
- some detail to the commit message (so that if this breaks people and they bisect it, they can easily find what's going on), and
- a comment to the code that explains the situation (because it isn't obvious why
connClose
doesn't just call close, and it's not an easy topic, so I think comments are warranted)
Ideally also a link to issue #673.
warp/Network/Wai/Handler/Warp/Run.hs
Outdated
@@ -64,7 +64,7 @@ socketConnection s = do | |||
connSendMany = Sock.sendMany s | |||
, connSendAll = sendall | |||
, connSendFile = sendFile s writeBuf bufferSize sendall | |||
, connClose = close s | |||
, connClose = shutdown s ShutdownSend `E.catch` \(SomeException _) -> return () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why is it sufficient to call
shutdown
but neverclose
afterwards? - What if
shutdown()
returnsENOTCONN
, do we leak the socket? - Is the catch-all exception handler good, or should it be more specific, so that we can observe bugs in the code? For example, should it not be at max some
IOError
? Should it perhaps be even specific to someerrno
we can expect, likeENOTCONN
? - Of the 4 steps I list in Missing response for certain POST requests nodejs/node#12339 (comment), this does only 2 steps. Don't we have to
- Keep
read()
ing from the socket until the empty string is read - Call
close()
on the socket
- Keep
- What about the case of misbehaving clients that never close their side? Will they be able to drain resources from the server by keeping ports open? Should there be some timeout/setting/mechanism to
close()
if the other side doesn'tclose()
after some expected duration?
Even if these are fine, I think it deverses a code comment why they are fine.
|
As you can see, |
It is already Saturday in Japan. So, I will answer other stuffs in Monday. |
@snoyberg I guess that it's better for WarpTLS to use |
I'd defer to @nh2 on my review, his points subsume what I noticed. The biggest question I was left with was why not do both shutdown and close. |
Oh, also: making the same change to warp-tls would make sense to me. |
Quick reply: |
Is that true? It contradicts my understanding of
The second sentence suggests that you can continue to use the socket FD in some ways after calling That is in line with what I wrote in the link and text posted in my detail comment above: #759 (comment) |
@nh2 You are right. I considered only normal cases. I will consider error cases. |
@nh2 I rewrote the code and did I'm not 100% convinced yet. What happens if TCP FIN is not returned from the client while receiving data? Does TCP timeout surely happen? |
|
OK. As one of maintainers of the |
I did |
@snoyberg It appeared that this PR makes the tests very slow. This is probably because |
There's nothing currently. If I added something on |
Yes, of course! |
Actually, there might be a simpler solution: how about setting |
@snoyberg It works. Thanks! But testing is still slow for other reasons. I try to understand where the slow down comes from. |
07e074e
to
70364b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
is called immediately. This is reported in yesodweb#673. We can reproduce this with h2spec: % h2spec http2/5.4 http2/7 5. Streams and Multiplexing 5.4. Error Handling 5.4.1. Connection Error Handling × 1: Sends an invalid PING frame for connection close -> The endpoint MUST close the TCP connection Expected: Connection closed Actual: Error: read tcp 127.0.0.1:56529->127.0.0.1:80: read: connection reset by peer 7. Error Codes × 1: Sends a GOAWAY frame with unknown error code -> The endpoint MUST NOT trigger any special behavior. Expected: Connection closed PING Frame (length:8, flags:0x01, stream_id:0, opaque_data:h2spec) Actual: Error: read tcp 127.0.0.1:56578->127.0.0.1:80: read: connection reset by peer To fix this, we use "gracefulClose" in the network library.
70364b4
to
aee7377
Compare
Since the PR of |
This patch lets Warp to use
shutdown
instead ofclose
.Background: when Warp sends GOAWAY in HTTP/2,
close
is called immediately. The kernel of the browser sends TCP ACK regarding to GOAWAY, but the socket of the server is already closed. So, TCP RST is sent back from the server to the client."UNIX Network Programming" suggests to use
shutdown
withSHUT_WR
. This makes sure that the TCP ACK is processed in the server properly and the socket is closed in the proper timing. Note that the combination ofLinger
andclose
does not help.h2spec
finds.lsof -p
in the field.Cc: @nh2