summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorNikhil Ladha <nladha@redhat.com>2021-02-10 15:07:32 +0530
committerGitHub <noreply@github.com>2021-02-10 10:37:32 +0100
commit5223300bc65eb88a1fbe27bd2702dbb92768cb27 (patch)
treea64ecc4a5951d66c07703497108cb878c9f627a1 /rpc
parent2572f096b2e6477e49009550d68e761e67676cc4 (diff)
downloadglusterfs-5223300bc65eb88a1fbe27bd2702dbb92768cb27.tar.gz
glusterfs-5223300bc65eb88a1fbe27bd2702dbb92768cb27.tar.xz
glusterfs-5223300bc65eb88a1fbe27bd2702dbb92768cb27.zip
glusterd: fix for starting brick on new port (#2090)
The Errno set by the runner code was not correct when the bind() fails to assign an already occupied port in the __socket_server_bind(). Fix: Updated the code to return the correct errno from the __socket_server_bind() if the bind() fails due to EADDRINUSE error. And, use the returned errno from runner_run() to retry allocating a new port to the brick process. Fixes: #1101 Change-Id: If124337f41344a04f050754e402490529ef4ecdc Signed-off-by: nik-redhat nladha@redhat.com
Diffstat (limited to 'rpc')
-rw-r--r--rpc/rpc-transport/socket/src/socket.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index ed8b473be2..b04847c223 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -948,6 +948,13 @@ __socket_server_bind(rpc_transport_t *this)
this->myinfo.identifier, strerror(errno));
if (errno == EADDRINUSE) {
gf_log(this->name, GF_LOG_ERROR, "Port is already in use");
+ ret = -EADDRINUSE;
+
+ /* TODO: Remove this delay. It was added only to address
+ * failures in the regression test suite, In a real
+ * situation, if a port is in use when the process starts,
+ * it most likely will remain in use during 10 seconds as
+ * well.*/
sleep(1);
retries--;
} else {
@@ -957,19 +964,9 @@ __socket_server_bind(rpc_transport_t *this)
break;
}
}
- } else {
- ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
- this->myinfo.sockaddr_len);
+ if (ret < 0)
+ goto out;
- if (ret != 0) {
- gf_log(this->name, GF_LOG_ERROR, "binding to %s failed: %s",
- this->myinfo.identifier, strerror(errno));
- if (errno == EADDRINUSE) {
- gf_log(this->name, GF_LOG_ERROR, "Port is already in use");
- }
- }
- }
- if (AF_UNIX != SA(&this->myinfo.sockaddr)->sa_family) {
if (getsockname(priv->sock, SA(&this->myinfo.sockaddr),
&this->myinfo.sockaddr_len) != 0) {
gf_log(this->name, GF_LOG_WARNING,
@@ -985,6 +982,17 @@ __socket_server_bind(rpc_transport_t *this)
"process started listening on port (%d)",
cmd_args->brick_port);
}
+ } else {
+ ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len);
+
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR, "binding to %s failed: %s",
+ this->myinfo.identifier, strerror(errno));
+ if (errno == EADDRINUSE) {
+ gf_log(this->name, GF_LOG_ERROR, "Port is already in use");
+ }
+ }
}
out: