summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohit Agrawal <moagrawal@redhat.com>2019-08-13 18:45:43 +0530
committerMOHIT AGRAWAL <moagrawa@redhat.com>2019-08-19 11:41:31 +0000
commitb4fe161741ba911cc2559a6b09cc20bc424880d7 (patch)
tree618718e076e64f46ca38979b40b38f9415fdd3e1
parent87745b612ae3a5a12fbac8162920d12b0dce0a66 (diff)
rpc: glusterd start is failed and throwing an error Address already in use
Problem: Some of the .t are failed due to bind is throwing an error EADDRINUSE Solution: After killing all gluster processes .t is trying to start glusterd but somehow if kernel has not cleaned up resources(socket) then glusterd startup is failed due to bind system call failure.To avoid the issue retries to call bind 10 times to execute system call succesfully > Change-Id: Ia5fd6b788f7b211c1508c1b7304fc08a32266629 > Fixes: bz#1743020 > Signed-off-by: Mohit Agrawal <moagrawal@redhat.com> > (cherry picked from commit c370c70f77079339e2cfb7f284f3a2fb13fd2f97) Change-Id: Ia5fd6b788f7b211c1508c1b7304fc08a32266629 Fixes: bz#1743218 Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
-rw-r--r--rpc/rpc-transport/socket/src/socket.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 4af8022f71d..a5a1f2db88d 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -925,6 +925,8 @@ __socket_server_bind(rpc_transport_t *this)
int ret = -1;
int opt = 1;
int reuse_check_sock = -1;
+ uint16_t sin_port = 0;
+ int retries = 0;
GF_VALIDATE_OR_GOTO("socket", this, out);
GF_VALIDATE_OR_GOTO("socket", this->private, out);
@@ -957,14 +959,42 @@ __socket_server_bind(rpc_transport_t *this)
}
}
- ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
- this->myinfo.sockaddr_len);
+ if (AF_UNIX != SA(&this->myinfo.sockaddr)->sa_family) {
+ sin_port = (int)ntohs(
+ ((struct sockaddr_in *)&this->myinfo.sockaddr)->sin_port);
+ if (!sin_port) {
+ sin_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
+ ((struct sockaddr_in *)&this->myinfo.sockaddr)->sin_port = htons(
+ sin_port);
+ }
+ retries = 10;
+ while (retries) {
+ ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len);
+ if (ret == -1) {
+ 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");
+ sleep(1);
+ retries--;
+ } else {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ } else {
+ ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len);
- if (ret == -1) {
- 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 (ret == -1) {
+ 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) {