-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Proposal Details
Proposal: Add the following to the net package:
// ErrRetryableAcceptError indicates a Listener.Accept error may be transient,
// and that a future call to Accept may succeed. This error is usually wrapped
// in another error, and should be tested for with errors.Is(err, ErrRetryableAcceptError).
//
// Accept errors corresponding to the errno values EMFILE, ENFILE, ECONNRESET, and ECONNABORTED
// match this error.
var ErrRetryableAcceptError = errors.New("ErrRetryableAcceptError")
Implementation will be to add an Is method to net.OpError which performs the appropriate check.
Background/rationale:
Some of the errors returned by net.Listener.Accept are potentially transient: While they indicate that the Accept call has failed, a future call may succeed.
Examples include:
EMFILE: the process is out of file descriptorsENFILE: the system is out of file descriptorsECONNRESETandECONNABORTED: see net/http: possible issues with temporary errors from Accept #6163
A server which calls Accept may want to ignore all these errors and call Accept again, probably after some backoff period. One of the uses for the deprecated net.Error.Temporary method is to check for these conditions, since we report all of the above as "temporary" errors.
As an example, net/http.Server uses net.Error.Temporary to retry potentially-transient Accept errors.
With the deprecation of net.Error.Temporary there is no non-deprecated way to test for these conditions. Temporary was deprecated, not because it isn't useful to test for retryable Accept errors but because the Temporary condition was ill-defined for many other errors, conflated transient errors with timeouts, and was just generally misunderstood. (See #45729.) I propose adding ErrRetryableAcceptError to provide a focused and reasonable well-defined replacement for the specific use case of Accept loops.
As an alternative, it might be nice if Accept just worked and didn't require the user to check for transient errors. However, that would require changing long-established behavior, and defining correct handling of EMFILE (for one example) seems challenging. This proposal is less ambitious in scope.
Further references:
Metadata
Metadata
Assignees
Labels
Type
Projects
Status