Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for the socket timeout functions #27773
Comments
alexcrichton
added
T-libs
B-unstable
labels
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
|
cc @sfackler |
alexcrichton
added
E-easy
final-comment-period
labels
Aug 13, 2015
This comment has been minimized.
This comment has been minimized.
|
This feature is now entering its final comment period for stabilization. |
This comment has been minimized.
This comment has been minimized.
|
It was pointed out in a hyper issue that the returned error when a timeout is hit is OS dependent. It might be helpful to include a
An alternative would be to normalize them into 1 type, but that seems more controversial. |
This comment has been minimized.
This comment has been minimized.
|
I would like them to be normalized into one kind of error, not doing so will make code that uses these APIs non-cross-platform by default, which is very unfortunate IMO. |
This comment has been minimized.
This comment has been minimized.
|
It's actually worse than the error codes just being inconsistent: on Windows, recv() returns WSAETIMEDOUT both when the receive call times out and when the connection itself times out, so you can't tell if the connection is still alive. |
This comment has been minimized.
This comment has been minimized.
|
What does it mean for a socket itself to time out? On Thu, Sep 3, 2015, 4:38 AM eefriedman notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
Err, sorry, I meant the connection, not the socket. |
This comment has been minimized.
This comment has been minimized.
|
Is the connection timing out in reference to TCP keepalive or something? |
This comment has been minimized.
This comment has been minimized.
|
@seanmonstar, @reem, my personal inclination is to do what we do in the rest of |
This comment has been minimized.
This comment has been minimized.
It's a bit more general than that: it means that the network stack closed the connection because it couldn't get a response from the other end. That doesn't necessarily mean a keepalive; it could also mean that it hit the general retransmission limit. @alexcrichton The problem here isn't precisely the portability of error codes; it's that recv() on Windows claims the connection is dead when it actually isn't. This means portable code must assume the connection is dead if the read timeout expires, so people will write code on Unix and find that there's no way to replicate the behavior on Windows without switching from std::net to some other networking library. |
This comment has been minimized.
This comment has been minimized.
I'm not sure I agree with that characterization, though I know we had many debates about how to handle errors :-) In particular, though, we strove for cross-platform behavior wherever reasonable while also avoiding laying on extra semantics or overhead. Of course, the hard cases are when these constraints are at odds. From my perspective, if there's a reasonably clear way to merge or reinterpret errors so that they are consistent across platforms without information loss, I prefer doing so. The downside is that it's more difficult to map back to the underlying system error. (IIRC we ended up having a single mapping function from system errors to our IO errors, so what I'm suggesting is indeed somewhat of a departure.) Failing that, it's not too bad if there are multiple errors you might get depending on the platform, as long as there's a reasonable, robust way to program against them that doesn't require It's not clear whether we can achieve either of these, though, without layering on some extra checking/semantics on the Windows side -- but I haven't dug into the specifics too much. Can someone more familiar with the details propose an alternative that favors cross-platform semantics? |
This comment has been minimized.
This comment has been minimized.
|
Alternative: don't use SO_RCVTIMEO or SO_SNDTIMEO because the semantics aren't portable. (Even if you ignore the Windows issues, the semantics are slightly different on Linux vs. *BSD.) Instead, use non-blocking sockets and select() to implement the intended functionality. |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 10, 2015
alexcrichton
referenced this issue
Sep 10, 2015
Merged
std: Stabilize/deprecate features for 1.4 #28339
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 10, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 10, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 10, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 10, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 11, 2015
This comment has been minimized.
This comment has been minimized.
|
We discussed the issues in this thread fairly extensively in the last libs team meeting. The consensus was to follow the philosophy laid out in @alexcrichton's earlier comment: rather than trying to layer on additional semantics for cross-platform compatibility, we optimize for transparency, where IO functionality has a clear mapping to system APIs -- including errors. That means, in particular, sticking with a single global mapping of OS error codes to our IO error kinds. This strategy is contingent on clear documentation of platform-specific behavior, and the ability to provide additional layers, in |
alexcrichton commentedAug 12, 2015
This is a tracking issue for the unstable
socket_timeoutfeature in the standard library. Now that theDurationtype is stable it may be the case that these methods can just be stabilized as-is.