Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d00b8af8
Unverified
Commit
d00b8af8
authored
Jul 21, 2022
by
Tian
Committed by
GitHub
Jul 20, 2022
Browse files
Don't update node ip when peer fd is closed (#10696)
parent
6d6e932f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
d00b8af8
...
@@ -1763,12 +1763,18 @@ void clusterProcessGossipSection(clusterMsg *hdr, clusterLink *link) {
...
@@ -1763,12 +1763,18 @@ void clusterProcessGossipSection(clusterMsg *hdr, clusterLink *link) {
/* IP -> string conversion. 'buf' is supposed to at least be 46 bytes.
/* IP -> string conversion. 'buf' is supposed to at least be 46 bytes.
* If 'announced_ip' length is non-zero, it is used instead of extracting
* If 'announced_ip' length is non-zero, it is used instead of extracting
* the IP from the socket peer address. */
* the IP from the socket peer address. */
void
nodeIp2String
(
char
*
buf
,
clusterLink
*
link
,
char
*
announced_ip
)
{
int
nodeIp2String
(
char
*
buf
,
clusterLink
*
link
,
char
*
announced_ip
)
{
if
(
announced_ip
[
0
]
!=
'\0'
)
{
if
(
announced_ip
[
0
]
!=
'\0'
)
{
memcpy
(
buf
,
announced_ip
,
NET_IP_STR_LEN
);
memcpy
(
buf
,
announced_ip
,
NET_IP_STR_LEN
);
buf
[
NET_IP_STR_LEN
-
1
]
=
'\0'
;
/* We are not sure the input is sane. */
buf
[
NET_IP_STR_LEN
-
1
]
=
'\0'
;
/* We are not sure the input is sane. */
return
C_OK
;
}
else
{
}
else
{
connPeerToString
(
link
->
conn
,
buf
,
NET_IP_STR_LEN
,
NULL
);
if
(
connPeerToString
(
link
->
conn
,
buf
,
NET_IP_STR_LEN
,
NULL
)
==
C_ERR
)
{
serverLog
(
LL_NOTICE
,
"Error converting peer IP to string: %s"
,
link
->
conn
?
connGetLastError
(
link
->
conn
)
:
"no link"
);
return
C_ERR
;
}
return
C_OK
;
}
}
}
}
...
@@ -1800,7 +1806,11 @@ int nodeUpdateAddressIfNeeded(clusterNode *node, clusterLink *link,
...
@@ -1800,7 +1806,11 @@ int nodeUpdateAddressIfNeeded(clusterNode *node, clusterLink *link,
* it is safe to call during packet processing. */
* it is safe to call during packet processing. */
if
(
link
==
node
->
link
)
return
0
;
if
(
link
==
node
->
link
)
return
0
;
nodeIp2String
(
ip
,
link
,
hdr
->
myip
);
/* If the peer IP is unavailable for some reasons like invalid fd or closed
* link, just give up the update this time, and the update will be retried
* in the next round of PINGs */
if
(
nodeIp2String
(
ip
,
link
,
hdr
->
myip
)
==
C_ERR
)
return
0
;
if
(
node
->
port
==
port
&&
node
->
cport
==
cport
&&
node
->
pport
==
pport
&&
if
(
node
->
port
==
port
&&
node
->
cport
==
cport
&&
node
->
pport
==
pport
&&
strcmp
(
ip
,
node
->
ip
)
==
0
)
return
0
;
strcmp
(
ip
,
node
->
ip
)
==
0
)
return
0
;
...
@@ -2253,7 +2263,7 @@ int clusterProcessPacket(clusterLink *link) {
...
@@ -2253,7 +2263,7 @@ int clusterProcessPacket(clusterLink *link) {
clusterNode
*
node
;
clusterNode
*
node
;
node
=
createClusterNode
(
NULL
,
CLUSTER_NODE_HANDSHAKE
);
node
=
createClusterNode
(
NULL
,
CLUSTER_NODE_HANDSHAKE
);
nodeIp2String
(
node
->
ip
,
link
,
hdr
->
myip
);
serverAssert
(
nodeIp2String
(
node
->
ip
,
link
,
hdr
->
myip
)
==
C_OK
)
;
node
->
port
=
ntohs
(
hdr
->
port
);
node
->
port
=
ntohs
(
hdr
->
port
);
node
->
pport
=
ntohs
(
hdr
->
pport
);
node
->
pport
=
ntohs
(
hdr
->
pport
);
node
->
cport
=
ntohs
(
hdr
->
cport
);
node
->
cport
=
ntohs
(
hdr
->
cport
);
...
...
src/connection.c
View file @
d00b8af8
...
@@ -389,7 +389,11 @@ int connGetSocketError(connection *conn) {
...
@@ -389,7 +389,11 @@ int connGetSocketError(connection *conn) {
}
}
int
connPeerToString
(
connection
*
conn
,
char
*
ip
,
size_t
ip_len
,
int
*
port
)
{
int
connPeerToString
(
connection
*
conn
,
char
*
ip
,
size_t
ip_len
,
int
*
port
)
{
return
anetFdToString
(
conn
?
conn
->
fd
:
-
1
,
ip
,
ip_len
,
port
,
FD_TO_PEER_NAME
);
if
(
anetFdToString
(
conn
?
conn
->
fd
:
-
1
,
ip
,
ip_len
,
port
,
FD_TO_PEER_NAME
)
==
-
1
)
{
if
(
conn
)
conn
->
last_errno
=
errno
;
return
C_ERR
;
}
return
C_OK
;
}
}
int
connSockName
(
connection
*
conn
,
char
*
ip
,
size_t
ip_len
,
int
*
port
)
{
int
connSockName
(
connection
*
conn
,
char
*
ip
,
size_t
ip_len
,
int
*
port
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment