[sheepdog] [PATCH] sockfd_cache: close socket always when node is crashed
MORITA Kazutaka
morita.kazutaka at gmail.com
Thu May 2 04:48:15 CEST 2013
At Thu, 02 May 2013 10:08:24 +0800,
Liu Yuan wrote:
>
> On 05/02/2013 12:50 AM, MORITA Kazutaka wrote:
> > @@ -498,7 +504,7 @@ void sheep_del_sockfd(const struct node_id *nid, struct sockfd *sfd)
> > return;
> > }
> >
> > - sockfd_cache_put(nid, sfd->idx);
> > + sockfd_cache_put(nid, sfd->idx, true);
> > sockfd_cache_del(nid);
> > free(sfd);
> > }
>
> sockfd_cache_del don't close fd correctly? If so it is better to add
> handling code in sockfd_cache_destroy() to close timeout-fd and pass idx
> to sockfd_cache_del directly.
I tried to close the fd in sockfd_cache_del() first, but found that
there is a race condition that the timeout fd can be used after
sockfd_cache_put() sets false to sockfd_cache_fd.in_use and before
sockfd_cache_del() closes the fd. We have to set false to fd.in_use
and close the timeout fd in the same lock context.
Another approach is removing sockfd_cache_put() from
sheep_del_sockfd(), and setting false to fd.in_use in
sockfd_cache_del(). I didn't take this approach because it needs more
modifications and would break the current stable code.
Thanks,
Kazutaka
More information about the sheepdog
mailing list