On 01/14/2016 06:22 PM, A. Mark wrote:
> OS:Linux Fedora 20 x86_64
>
> I'm getting the following segfault/abort:
>
> "close failed" from libmicrohttpd v0.9.46.
>
> I traced the issue to the following code in daemon.c:
>
> ---
> /* epoll documentation suggests that closing a FD
> automatically removes it from the epoll set; however,
> this is not true as if we fail to do manually remove it,
> we are still seeing an event for this fd in epoll,
> causing grief (use-after-free...) --- at least on my
> system. */
> if (0 != epoll_ctl (daemon->epoll_fd,
> EPOLL_CTL_DEL,
> pos->socket_fd,
> NULL))
> MHD_PANIC ("Failed to remove FD from epoll set\n");
> pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
> }
> #endif
> if (NULL != pos->response)
> {
> MHD_destroy_response (pos->response);
> pos->response = NULL;
> }
> if (MHD_INVALID_SOCKET != pos->socket_fd)
> {
> #ifdef WINDOWS
> shutdown (pos->socket_fd, SHUT_WR);
> #endif
> if (0 != MHD_socket_close_ (pos->socket_fd))
> * MHD_PANIC ("close failed\n");*
> }
> ---
>
> Any remedies? This suggests that there is an issue with epoll?
> <[email protected]>I don't see why you say that. The comment you quote justifies why we call EPOLL_CTL_DEL in addition to close(), it doesn't explain why close() may later return an error code here. You might want to first investigate what type of error close() returns here (check 'errno'). Assuming it is a 'fd already closed', we need to figure out which code did already close the FD (and failed to set 'pos->socket_fd' to MHD_INVALID_SOCKET. Note that this could be a problem in your application logic: if your application closes() an FD that doesn't belong to it, you would get this error as well. If we find that this very FD was (last) closed by MHD (and where), then we can identify and fix the cause. If you want us to help, a testcase to reproduce this would be wonderful. Other than that, you need to do a bit more debugging ;-). Regardless, based on the limited information you provided. I suspect this is rather unlikely to be EPOLL-related,
signature.asc
Description: OpenPGP digital signature
