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

Draft
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

OlgaMaciaszek
Copy link
Contributor

This is related to spring-cloud/spring-cloud-netflix#4094 as an attempted fix.

@OlgaMaciaszek OlgaMaciaszek force-pushed the 2.x-use-lock-for-instance-status-update branch from f7d808d to ca2d613 Compare December 24, 2024 11:45
logger.warn("Exception from healthcheckHandler.getStatus, setting status to DOWN", e);
status = InstanceStatus.DOWN;
}
if (instanceStatusUpdateLock.tryLock()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need the fix here? Since both threads will call healthcheck to find latest status, unless healthcheck itself is flipping, the status would be the same? Maybe there is a race in update sequence, but the value would be consistent?

Copy link
Contributor Author

@OlgaMaciaszek OlgaMaciaszek Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @howardyuan, thanks for the comment. You're right. I've taken another look at it and I now think the approach to take could be to have a compareAndSet logic while changing InstanceInfo.InstanceStatus within DiscoveryClient#refreshInstanceInfo to prevent a situation where the status has been changed by the other thread between getting original status from the field and setting its transformed value there. Could be done by changing that field into an actual AtomicReference or, to remain consistent with the current class implementation and avoid having to change/ add too many methods, keeping it as a volatile field and adding a synchronized method in that class that would first compare the expected field value with the actual one and calling that new method within DiscoveryClient#refreshInstanceInfo. Let me know what you think.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your suggestions of comparing before setting should be safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will work on it soon.

@OlgaMaciaszek OlgaMaciaszek marked this pull request as draft January 13, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants