Skip to content

Commit

Permalink
Fix race condition when host is stopping
Browse files Browse the repository at this point in the history
.. and ServerX509TrustManager is starting.

Change-Id: Id649d76f318ccf4720be430a28ef6d486f22dfbd
Reviewed-on: http://bellevue-ci.eng.vmware.com:8080/10330
Compute-Verified: jenkins <[email protected]>
Closures-Verified: jenkins <[email protected]>
Upgrade-Verified: jenkins <[email protected]>
Bellevue-Verified: jenkins <[email protected]>
CS-Verified: jenkins <[email protected]>
Reviewed-by: Lazarin Lazarov <[email protected]>
  • Loading branch information
jvassev committed May 23, 2017
1 parent 4a6ff6c commit fcf8c43
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target
*~
\#*#
build
.vscode/
!tools/build
lib/extjs/extjs/
.DS_Store
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2017 VMware, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product may include a number of subcomponents with separate copyright notices
* and license terms. Your use of these subcomponents is subject to the terms and
* conditions of the subcomponent's license, as noted in the LICENSE file.
*/

package com.vmware.admiral.common.util;

import java.lang.reflect.Field;

import com.vmware.xenon.common.Utils;

public final class TrustManagerResetter {
private TrustManagerResetter() {
}

public static void reset() {
try {
Field field = ServerX509TrustManager.class.getDeclaredField("INSTANCE");
field.setAccessible(true);
field.set(null, null);
} catch (Exception e) {
Utils.logWarning("Cannot reset ServerX509TrustManager");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ private void schedulePeriodicCertificatesReload() {
if (host.isStopping()) {
return;
}
host.schedule(() -> {

Runnable task = () -> {
try {
host.log(Level.INFO, "Host " + host.getPublicUri() + ": reloading all certificates");
documentUpdateTimeMicros = 0;
Expand All @@ -200,7 +201,13 @@ private void schedulePeriodicCertificatesReload() {

schedulePeriodicCertificatesReload();
}
}, nextDelay, TimeUnit.MICROSECONDS);
};

try {
host.schedule(task, nextDelay, TimeUnit.MICROSECONDS);
} catch (Exception e) {
host.log(Level.INFO, "Host is stopping");
}
}

@Override
Expand Down

0 comments on commit fcf8c43

Please sign in to comment.