From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 3 Dec 2018 19:16:58 +0300 From: Vladimir Davydov Subject: Re: [PATCH 07/11] coio: fix file descriptor leak on accept Message-ID: <20181203161658.mvag6vbepsurq6zk@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: Vladislav Shpilevoy Cc: tarantool-patches@freelists.org List-ID: On Fri, Nov 30, 2018 at 06:39:39PM +0300, Vladislav Shpilevoy wrote: > @@ -90,44 +92,46 @@ evio_setsockopt_keepalive(int fd) > */ > int keepcnt = 5; > if (sio_setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &keepcnt, > - sizeof(int))) > - diag_raise(); > + sizeof(int)) != 0) > + return -1; > int keepidle = 30; > > if (sio_setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepidle, > - sizeof(int))) > - diag_raise(); > + sizeof(int)) != 0) > + return -1; > > int keepintvl = 60; > if (sio_setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepintvl, > - sizeof(int))) > - diag_raise(); > + sizeof(int)) != 0) > + return -1; > #endif > + return 0; > } > > /** Set common client socket options. */ > -void > +int > evio_setsockopt_client(int fd, int family, int type) > { > int on = 1; > - /* In case this throws, the socket is not leaked. */ > if (sio_setfl(fd, O_NONBLOCK) != 0) > - diag_raise(); > + return -1; > if (type == SOCK_STREAM && family != AF_UNIX) { > /* > * SO_KEEPALIVE to ensure connections don't hang > * around for too long when a link goes away. > */ > - evio_setsockopt_keepalive(fd); > + if (evio_setsockopt_keepalive(fd) != 0) > + return -1; > /* > * Lower latency is more important than higher > * bandwidth, and we usually write entire > * request/response in a single syscall. > */ > if (sio_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, > - &on, sizeof(on))) > - diag_raise(); > + &on, sizeof(on)) != 0) > + return -1; > } > + return 0; > } > > /** Set options for server sockets. */ > @@ -150,8 +154,9 @@ evio_setsockopt_server(int fd, int family, int type) > if (sio_setsockopt(fd, SOL_SOCKET, SO_LINGER, > &linger, sizeof(linger))) > diag_raise(); > - if (type == SOCK_STREAM && family != AF_UNIX) > - evio_setsockopt_keepalive(fd); > + if (type == SOCK_STREAM && family != AF_UNIX && > + evio_setsockopt_keepalive(fd) != 0) > + diag_raise(); > } I don't like this patch, because apart from fixing the leak, it also removes exceptions from some evio functions, but not all of them, e.g. evio_setsockopt_keepalive and evio_setsockopt_client are now exception free while evio_setsockopt_server is not. And then you have a separate patch that removes the rest of exception from evio. Let's please first remove all exceptions from evio in one go, and only then fix the leak?