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

[core] Fix the KvQueryTableTest may stuck in loop #4328

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

Aitozi
Copy link
Contributor

@Aitozi Aitozi commented Oct 15, 2024

Purpose

Before, it use the pattern as bellow, which will lead the ConcurrentHashMap stuck in loop

Map<String, String> test = new ConcurrentHashMap<>();
test.computeIfAbsent(
        "a",
        new Function<String, String>() {
            @Override
            public String apply(String s) {
                return test.remove("a");
            }
        });
System.out.println(test);

The KvQueryTableTest will stuck in the thread as below

image

Tests

API and Format

Documentation

@wwj6591812
Copy link
Contributor

1、Does this must appear every time?
2、This is a bug in JDK?

@Aitozi
Copy link
Contributor Author

Aitozi commented Oct 16, 2024

1、Does this must appear every time? 2、This is a bug in JDK?

Map<String, String> test = new ConcurrentHashMap<>();
test.computeIfAbsent(
        "a",
        new Function<String, String>() {
            @Override
            public String apply(String s) {
                return test.remove("a");
            }
        });
System.out.println(test);

In jdk8 it will stuck, in jdk11 it will throw IllegalStageException. I think it's a wrong use case. So, we should avoid to modify the map in the computeIfAbsent call.

@JingsongLi
Copy link
Contributor

+1

@JingsongLi JingsongLi merged commit d3d6616 into apache:master Oct 16, 2024
12 checks passed
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