Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lock for instance status update. #1566

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
*
* @author Karthik Ranganathan, Greg Kim
* @author Spencer Gibb
* @author Olga Maciaszek-Sharma
*
*/
@Singleton
Expand Down Expand Up @@ -149,6 +150,7 @@ public class DiscoveryClient implements EurekaClient {
private final PreRegistrationHandler preRegistrationHandler;
private final AtomicReference<Applications> localRegionApps = new AtomicReference<>();
private final Lock fetchRegistryUpdateLock = new ReentrantLock();
private final ReentrantLock instanceStatusUpdateLock = new ReentrantLock();
// monotonically increasing generation counter to ensure stale threads do not reset registry to an older version
private final AtomicLong fetchRegistryGeneration;
private final ApplicationInfoManager applicationInfoManager;
Expand Down Expand Up @@ -1381,15 +1383,26 @@ void refreshInstanceInfo() {
applicationInfoManager.refreshLeaseInfoIfRequired();

InstanceStatus status;
try {
status = getHealthCheckHandler().getStatus(instanceInfo.getStatus());
} catch (Exception e) {
logger.warn("Exception from healthcheckHandler.getStatus, setting status to DOWN", e);
status = InstanceStatus.DOWN;
}
if (instanceStatusUpdateLock.tryLock()) {
try {
try {
status = getHealthCheckHandler().getStatus(instanceInfo.getStatus());
}
catch (Exception e) {
logger.warn("Exception from healthcheckHandler.getStatus, setting status to DOWN", e);
status = InstanceStatus.DOWN;
}

if (null != status) {
applicationInfoManager.setInstanceStatus(status);
if (null != status) {
applicationInfoManager.setInstanceStatus(status);
}
}
finally {
instanceStatusUpdateLock.unlock();
}
}
else {
logger.warn("Cannot acquire update lock, aborting instance status refresh");
}
}

Expand Down
Loading