Skip to content

Commit

Permalink
[Fix][Master] Fix Potential danger in the event of a worker failover (#…
Browse files Browse the repository at this point in the history
…15689)

* clean unused import

* fix style check

* fix when path is null or empty, it will cause serverhost is null,

* fix UT test (#15684)

* [Fix-15639] parameterPassing is null case NPE (#15678)

Co-authored-by: caishunfeng <[email protected]>

* fix  when path is null or empty, it will cause serverhost is null,
  • Loading branch information
ZhongJinHacker authored Mar 11, 2024
1 parent 2395ba5 commit 738da1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ public void removeMasterNodePath(String path, RegistryNodeType nodeType, boolean
public void removeWorkerNodePath(String path, RegistryNodeType nodeType, boolean failover) {
log.info("{} node deleted : {}", nodeType, path);
try {
String serverHost = null;
if (!StringUtils.isEmpty(path)) {
serverHost = registryClient.getHostByEventDataPath(path);
if (StringUtils.isEmpty(serverHost)) {
log.error("server down error: unknown path: {}", path);
return;
}
if (!registryClient.exists(path)) {
log.info("path: {} not exists", path);
}
if (StringUtils.isEmpty(path)) {
log.error("server down error: node empty path: {}, nodeType:{}", path, nodeType);
return;
}

String serverHost = registryClient.getHostByEventDataPath(path);
if (StringUtils.isEmpty(serverHost)) {
log.error("server down error: unknown path: {}", path);
return;
}
if (!registryClient.exists(path)) {
log.info("path: {} not exists", path);
}

// failover server
if (failover) {
failoverService.failoverServerWhenDown(serverHost, nodeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ public void removeNodePathTest() {
// Cannot mock static methods
masterRegistryClient.removeWorkerNodePath("/path", RegistryNodeType.WORKER, true);
}

@Test
public void removeWorkNodePathTest() {
masterRegistryClient.removeWorkerNodePath("", RegistryNodeType.WORKER, true);
masterRegistryClient.removeWorkerNodePath(null, RegistryNodeType.WORKER, true);
}
}

0 comments on commit 738da1c

Please sign in to comment.