From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 25 Feb 2019 20:08:29 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] [PATCH v2] iproto: close socket explicitly before wal_dir at exit Message-ID: <20190225170829.wit66yfadk4hk3zb@esperanza> References: <20190225145625.10840-1-i.kosarev@tarantool.org> <20190225165047.GF2663@chai> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190225165047.GF2663@chai> To: Konstantin Osipov Cc: tarantool-patches@freelists.org, i.kosarev@corp.mail.ru, Ilya Kosarev List-ID: On Mon, Feb 25, 2019 at 07:50:47PM +0300, Konstantin Osipov wrote: > * Ilya Kosarev [19/02/25 19:14]: > > +void > > +iproto_free() > > +{ > > + tt_pthread_cancel(net_cord.id); > > + tt_pthread_join(net_cord.id, NULL); > > + /* > > + * Close socket descriptor to prevent hot standby instance > > + * failing to bind in case it tries to bind > > + * before socket is closed by OS. > > + */ > > + close(binary.ev.fd); > > +} > > What if there is no socket descriptor in binary.ev.fd? > I understand it's OK to close a non-existing descriptor, but still > looks a bit messy to me. Yeah, missed that, sorry. Fixed as shown below: >From 37b883145ff0464640d917fe58b488eb7d539400 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov Date: Mon, 25 Feb 2019 20:03:27 +0300 Subject: [PATCH] iproto: don't attempt to close socket if it was not open This can't entail any consequences, because socket fd is set to -1 in this case, but this just looks a bit messy. Let's clean it up. Follow-up commit 305dbcf68953 ("iproto: close socket explicitly before wal_dir at exit"). diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 226b9d06..863eb4f0 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -2152,5 +2152,6 @@ iproto_free() * failing to bind in case it tries to bind before socket * is closed by OS. */ - close(binary.ev.fd); + if (evio_service_is_active(&binary)) + close(binary.ev.fd); }