Tarantool development patches archive
 help / color / mirror / Atom feed
From: Ilya Kosarev <i.kosarev@tarantool.org>
To: alyapunov@tarantool.org
Cc: Ilya Kosarev <ilyanapar@yandex.ru>, tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2] iproto: close socket explicitly before wal_dir at exit
Date: Fri, 14 Aug 2020 13:46:55 +0300	[thread overview]
Message-ID: <20200814104655.6760-1-i.kosarev@tarantool.org> (raw)

From: Ilya Kosarev <ilyanapar@yandex.ru>

tarantool instance didn't close socket explicitly
which could cause hot standby instance to fail to bind
in case it tries to bind before socket is closed by OS.
Now it is fixed by closing socket explicitly before wal_dir.

Closes #3967
---
https://github.com/tarantool/tarantool/tree/i.kosarev/gh-3967-close-socket-explicitly
https://github.com/tarantool/tarantool/issues/3967

 src/box/box.cc    |  1 +
 src/box/iproto.cc | 13 +++++++++++++
 src/box/iproto.h  |  3 +++
 3 files changed, 17 insertions(+)

diff --git a/src/box/box.cc b/src/box/box.cc
index e7ec2891c..73d94f79b 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1666,6 +1666,7 @@ box_free(void)
 		tuple_free();
 		port_free();
 #endif
+		iproto_free();
 		replication_free();
 		sequence_free();
 		gc_free();
diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index bea35ce87..b1d24910f 100644
--- a/src/box/iproto.cc
+++ b/src/box/iproto.cc
@@ -2080,3 +2080,16 @@ iproto_set_msg_max(int new_iproto_msg_max)
 	iproto_do_cfg(&cfg_msg);
 	cpipe_set_max_input(&net_pipe, new_iproto_msg_max / 2);
 }
+
+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);
+}
diff --git a/src/box/iproto.h b/src/box/iproto.h
index b9a6cf8f7..8f3607ffc 100644
--- a/src/box/iproto.h
+++ b/src/box/iproto.h
@@ -80,6 +80,9 @@ iproto_listen(const char *uri);
 void
 iproto_set_msg_max(int iproto_msg_max);
 
+void
+iproto_free();
+
 #endif /* defined(__cplusplus) */
 
 #endif
-- 
2.17.1

             reply	other threads:[~2020-08-14 10:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 10:46 Ilya Kosarev [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-02-25 14:56 Ilya Kosarev
2019-02-25 16:50 ` [tarantool-patches] " Konstantin Osipov
2019-02-25 17:08   ` Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200814104655.6760-1-i.kosarev@tarantool.org \
    --to=i.kosarev@tarantool.org \
    --cc=alyapunov@tarantool.org \
    --cc=ilyanapar@yandex.ru \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2] iproto: close socket explicitly before wal_dir at exit' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox