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

Implement semaphore synchronization to prevent concurrent modificatio…issue#4094 #4301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bazzop
Copy link

@bazzop bazzop commented Aug 24, 2024

…ns of InstanceStatus

Implement semaphore synchronization to prevent concurrent modifications of InstanceStatus

  • Added a Semaphore to control concurrent access to InstanceStatus modifications.
  • Modified EurekaClientConfigurationRefresher to acquire the semaphore before performing deregister and register operations.
  • Modified DiscoveryClientConfiguration to acquire the semaphore before performing refreshInstanceInfo operations.
  • Ensured the semaphore is released in a finally block to handle exceptions properly.

This change addresses the issue of concurrent modifications of InstanceStatus, ensuring that only one thread can modify the status at a time.

…ns of InstanceStatus

Implement semaphore synchronization to prevent concurrent modifications of InstanceStatus

- Added a Semaphore to control concurrent access to InstanceStatus modifications.
- Modified EurekaClientConfigurationRefresher to acquire the semaphore before performing deregister and register operations.
- Modified DiscoveryClientConfiguration to acquire the semaphore before performing refreshInstanceInfo operations.
- Ensured the semaphore is released in a finally block to handle exceptions properly.

This change addresses the issue of concurrent modifications of InstanceStatus, ensuring that only one thread can modify the status at a time.
@OlgaMaciaszek
Copy link
Collaborator

Fixes gh-4094.

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Hi @bazzop, thanks for submitting the PR. The build is failing on checkstyle. Please apply the necessary changes and make sure the build passes. Please address the comments I've added. Also, please submit your changes against 4.1.x instead of main so that we can get the bugfix also in the 2023.0.x release train.

@@ -51,52 +52,100 @@
@ConditionalOnBlockingDiscoveryEnabled
public class EurekaDiscoveryClientConfiguration {

@Bean
@ConditionalOnMissingBean
public EurekaDiscoveryClient discoveryClient(EurekaClient client, EurekaClientConfig clientConfig) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems you've changed formatting - as a result it shows as if you've modified all these lines of code. Please revert to our formatting (possibly a spaces/ tabs issue) so that it's clearly visible in the diff what code has been changed by you.

@@ -19,7 +19,6 @@
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the date in the license comment to 2013-2024.

@@ -35,6 +34,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Semaphore;

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add your full name with @author tag to the javadoc of the class.


void refreshInstanceInfo() {
try {
semaphore.acquire();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use binary semaphore rather than a ReentrantLock?

@Autowired
private InstanceInfo instanceInfo;

void refreshInstanceInfo() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems this method is not ever used - please verify and finish up your changes, and then request another review.

@OlgaMaciaszek
Copy link
Collaborator

Please mark your PR as "draft" until it's ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EurekaClientConfigurationRefresher & DiscoveryClient#refreshInstanceInfo concurrent execution
3 participants