[sheepdog] [PATCH] sheep/request: fix fd leak
Liu Yuan
namei.unix at gmail.com
Thu Jul 31 06:00:29 CEST 2014
On Thu, Jul 31, 2014 at 11:29:02AM +0800, Ruoyu wrote:
> This patch fixes fd leak in sheep process such as below in lsof command.
>
> sheep 15276 liangry 95u sock 0,7 0t0 465109 can't identify protocol
> sheep 15276 liangry 96u sock 0,7 0t0 464282 can't identify protocol
> sheep 15276 liangry 97u sock 0,7 0t0 464284 can't identify protocol
>
> Signed-off-by: Ruoyu <liangry at ucweb.com>
> ---
> sheep/request.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/sheep/request.c b/sheep/request.c
> index 2a24b93..a4d8ed0 100644
> --- a/sheep/request.c
> +++ b/sheep/request.c
> @@ -729,8 +729,14 @@ main_fn void put_request(struct request *req)
> eventfd_xwrite(req->local_req_efd, 1);
> else {
> if (ci->conn.dead) {
> - clear_client_info(ci);
> + /*
> + * free_request should be called prior to
> + * clear_client_info because refcnt of ci will
> + * be decreased in free_request. Otherwise, ci
> + * cannot be freed in clear_client_info.
> + */
> free_request(req);
> + clear_client_info(ci);
> } else {
> list_add_tail(&req->request_list, &ci->done_reqs);
>
> @@ -966,7 +972,14 @@ static void client_handler(int fd, int events, void *data)
>
> sd_debug("%x, %d", events, ci->conn.dead);
>
> - if (events & (EPOLLERR | EPOLLHUP) || ci->conn.dead)
> + if (events & (EPOLLERR | EPOLLHUP))
> + ci->conn.dead = true;
> + /*
> + * Although dead is true, ci might not be freed immediately
> + * because of refcnt. Never mind, we will complete it later
> + * as long as dead is true.
> + */
> + if (ci->conn.dead)
> return clear_client_info(ci);
>
> if (events & EPOLLIN) {
> --
> 1.8.3.2
>
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog
Applied thanks
Yuan
More information about the sheepdog
mailing list