Skip to content

Implement adequate response on poll failure #105

@552020

Description

@552020

This is the case when poll returns with < 0. It's not an error on the socket but an error on poll itself.

Yes, correctly handling errors returned by the poll function itself is critical for ensuring the stability and robustness of your server. The function name HandlePollFailure is descriptive and aptly chosen for a function intended to address poll errors. It conveys the purpose of the function clearly, aligning with best practices for naming functions by their actions or intentions.

Implementing HandlePollFailure

When implementing HandlePollFailure, you should consider the nature of errors poll can return and the most appropriate response to each. Here's a breakdown:

  1. EINTR (Interrupted System Call): This error occurs if poll was interrupted by a signal. The best practice in many cases is to retry the poll operation, as the interruption does not necessarily indicate a fatal error. Logging the interruption can be useful for debugging purposes.
  2. EBADF (Bad File Descriptor): This indicates one or more of the file descriptors provided to poll was not valid. This is a serious error that might indicate a logic error in your code and requires investigation.
  3. EFAULT (Bad Address): The addresses provided to poll are outside your accessible address space. This likely indicates a programming error and should be logged and investigated.
  4. EINVAL (Invalid Argument): Indicates an invalid argument to poll. This could be because the nfds value is negative or other invalid parameters. Like EBADF and EFAULT, this likely indicates a bug in your program.
  5. ENOMEM (Out of Memory): The kernel was unable to allocate memory for internal tables. This is a serious system-level error, suggesting that your system might be under heavy load or resource-constrained.

Responses to poll Failures

  • Retry on EINTR: A simple retry is often adequate.
  • Investigate and Fix for EBADF, EFAULT, EINVAL: These errors indicate bugs that need fixing in your code.
  • Handle ENOMEM Gracefully: If possible, free up resources and retry. If the issue persists, you may need to shutdown gracefully and alert an administrator.

Incorporating detailed logging and alert mechanisms in your error handling can greatly aid in diagnosing and responding to issues, especially for errors that indicate underlying systemic or logical issues.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions