Skip to content

Commit

Permalink
Use lock for instance status update.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMaciaszek committed Dec 23, 2024
1 parent f4c8ed1 commit f7d808d
Showing 1 changed file with 21 additions and 8 deletions.
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 @@ -1381,15 +1382,27 @@ 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;
}
ReentrantLock instanceStatusUpdateLock = new ReentrantLock();
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

0 comments on commit f7d808d

Please sign in to comment.