Skip to content

Commit

Permalink
*Fix graceful shutdown notify failure
Browse files Browse the repository at this point in the history
Signed-off-by: provenceee <[email protected]>
  • Loading branch information
provenceee committed Sep 24, 2024
1 parent 0e18da2 commit 7a34781
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/spring_integration_test_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@ jobs:
- name: (graceful) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: needs.set-execution-conditions.outputs.enableGraceful == 'true'
uses: ./.github/actions/scenarios/spring/graceful
- name: (spring common) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: needs.set-execution-conditions.outputs.enableSpringCommon == 'true'
uses: ./.github/actions/scenarios/spring/spring-common
- name: (nacos dynamic config) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: ${{ matrix.nacosVersion != '' && needs.set-execution-conditions.outputs.enableDynamicConfig == 'true' }}
uses: ./.github/actions/scenarios/spring/dynamic-config-nacos
- name: (zk dynamic config) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: needs.set-execution-conditions.outputs.enableDynamicConfig == 'true'
uses: ./.github/actions/scenarios/spring/dynamic-config-zk
- name: monitor test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: needs.set-execution-conditions.outputs.enableSpringMonitor == 'true'
uses: ./.github/actions/scenarios/spring/monitor
- name: visibility test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: needs.set-execution-conditions.outputs.enableSpringVisibility == 'true'
uses: ./.github/actions/scenarios/spring/visibility
- name: removal test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
if: needs.set-execution-conditions.outputs.enableSpringRemoval == 'true'
uses: ./.github/actions/scenarios/spring/removal
# - name: (spring common) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
# if: needs.set-execution-conditions.outputs.enableSpringCommon == 'true'
# uses: ./.github/actions/scenarios/spring/spring-common
# - name: (nacos dynamic config) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
# if: ${{ matrix.nacosVersion != '' && needs.set-execution-conditions.outputs.enableDynamicConfig == 'true' }}
# uses: ./.github/actions/scenarios/spring/dynamic-config-nacos
# - name: (zk dynamic config) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
# if: needs.set-execution-conditions.outputs.enableDynamicConfig == 'true'
# uses: ./.github/actions/scenarios/spring/dynamic-config-zk
# - name: monitor test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
# if: needs.set-execution-conditions.outputs.enableSpringMonitor == 'true'
# uses: ./.github/actions/scenarios/spring/monitor
# - name: visibility test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
# if: needs.set-execution-conditions.outputs.enableSpringVisibility == 'true'
# uses: ./.github/actions/scenarios/spring/visibility
# - name: removal test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }}
# if: needs.set-execution-conditions.outputs.enableSpringRemoval == 'true'
# uses: ./.github/actions/scenarios/spring/removal
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public class GraceShutdownBehavior implements Runnable {

@Override
public void run() {
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "GraceShutdownBehavior run");
if (graceConfig.isEnableSpring() && graceConfig.isEnableGraceShutdown()) {
GraceContext.INSTANCE.getGraceShutDownManager().setShutDown(true);
graceService = PluginServiceManager.getPluginService(GraceService.class);
graceShutDown();
}
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "GraceShutdownBehavior finish");
}

private void graceShutDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CommonUtils {
try {
Thread.sleep(time);
} catch (InterruptedException ex) {
System.out.println("Sleep has been interrupted!");
LOGGER.fine("Sleep has been interrupted!");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class GraceServiceImpl implements GraceService {
*/
@Override
public void shutdown() {
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "GraceServiceImpl run");
if (SHUTDOWN.compareAndSet(false, true)) {
Object registration = GraceContext.INSTANCE.getGraceShutDownManager().getRegistration();
ReflectUtils.invokeMethodWithNoneParameter(registration, REGISTRATION_DEREGISTER_METHOD_NAME);
Expand All @@ -91,6 +92,7 @@ public void shutdown() {
Thread.currentThread().getName() + LocalDateTime.now() + "latch count is " + latch.getCount());
AddressCache.INSTANCE.getAddressSet().forEach(address -> notifyToGraceHttpServer(address, header));
}
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "GraceServiceImpl run");
}

@Override
Expand Down Expand Up @@ -124,6 +126,7 @@ private void execute(String address, Map<String, Collection<String>> header) {
GRACE_HTTP_SERVER_PROTOCOL + address + GraceConstants.GRACE_NOTIFY_URL_PATH,
REQUEST_BODY, header);
if (result.getCode() == GraceConstants.GRACE_HTTP_SUCCESS_CODE) {
System.out.println("Succeed to notify before shutdown, address: " + address);
break;
}
System.out.println("Failed to notify before shutdown, address: " + address);
Expand Down

0 comments on commit 7a34781

Please sign in to comment.