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

Fix circular dependency in Settings initialization #10194

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

msfroh
Copy link
Collaborator

@msfroh msfroh commented Sep 22, 2023

Description

There was a weird circular class-loading dependency between Settings and Settings.Builder that could result in ClassLoader deadlock if multiple threads trigger class-loading of Settings at the same time.

Related Issues

Resolves #10065

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions github-actions bot added bug Something isn't working Clients Clients within the Core repository such as High level Rest client and low level client labels Sep 22, 2023
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT:
  • URL:
  • CommitID: e7b2082
    Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green.
    Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2023

Compatibility status:

Checks if related components are compatible with change 1c79c83

Incompatible components

Skipped components

Compatible components

Compatible components: [https://github.com/opensearch-project/security.git, https://github.com/opensearch-project/alerting.git, https://github.com/opensearch-project/index-management.git, https://github.com/opensearch-project/anomaly-detection.git, https://github.com/opensearch-project/sql.git, https://github.com/opensearch-project/job-scheduler.git, https://github.com/opensearch-project/asynchronous-search.git, https://github.com/opensearch-project/observability.git, https://github.com/opensearch-project/common-utils.git, https://github.com/opensearch-project/k-nn.git, https://github.com/opensearch-project/reporting.git, https://github.com/opensearch-project/cross-cluster-replication.git, https://github.com/opensearch-project/security-analytics.git, https://github.com/opensearch-project/custom-codecs.git, https://github.com/opensearch-project/performance-analyzer.git, https://github.com/opensearch-project/ml-commons.git, https://github.com/opensearch-project/opensearch-oci-object-storage.git, https://github.com/opensearch-project/performance-analyzer-rca.git, https://github.com/opensearch-project/geospatial.git, https://github.com/opensearch-project/notifications.git, https://github.com/opensearch-project/neural-search.git]

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      1 org.opensearch.remotestore.RemoteStoreStatsIT.testStatsResponseAllShards

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #10194 (1c79c83) into main (d656e3d) will decrease coverage by 0.08%.
Report is 4 commits behind head on main.
The diff coverage is 69.44%.

@@             Coverage Diff              @@
##               main   #10194      +/-   ##
============================================
- Coverage     71.24%   71.17%   -0.08%     
- Complexity    58260    58296      +36     
============================================
  Files          4830     4830              
  Lines        274575   274586      +11     
  Branches      40015    40020       +5     
============================================
- Hits         195629   195434     -195     
- Misses        62570    62799     +229     
+ Partials      16376    16353      -23     
Files Coverage Δ
.../java/org/opensearch/common/settings/Settings.java 80.62% <100.00%> (ø)
...org/opensearch/index/search/stats/SearchStats.java 82.02% <0.00%> (ø)
...java/org/opensearch/index/shard/IndexingStats.java 86.61% <0.00%> (ø)
...rg/opensearch/repositories/s3/S3BlobContainer.java 79.15% <76.66%> (-1.08%) ⬇️

... and 450 files with indirect coverage changes

@dblock
Copy link
Member

dblock commented Sep 28, 2023

LGTM, want to finish it?

@msfroh msfroh changed the title Simplify initialization of Settings Fix circular dependency in Settings initialization Sep 29, 2023
@msfroh msfroh force-pushed the settings_initialization branch from e7b2082 to 7283363 Compare September 29, 2023 19:30
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT:
  • URL:
  • CommitID: 7283363
    Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green.
    Is the failure a flaky test unrelated to your change?

1 similar comment
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT:
  • URL:
  • CommitID: 7283363
    Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green.
    Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.

Signed-off-by: Michael Froh <froh@amazon.com>
@msfroh msfroh force-pushed the settings_initialization branch from 7283363 to 1c79c83 Compare September 30, 2023 16:31
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@msfroh
Copy link
Collaborator Author

msfroh commented Sep 30, 2023

I was able to reproduce the deadlock with the following simple class:

public class SettingsMain {
    public static void main(String[] args) {
        new Thread(Settings.Builder.EMPTY_SETTINGS::getSecureSettings).start();
        Settings.builder();
    }
}

When I run that, the process just hangs. (It's essentially the idea discussed in https://www.farside.org.uk/201510/deadlocks_in_java_class_initialisation.)

With the code change from this PR, it doesn't hang -- it just completes immediately.

@msfroh
Copy link
Collaborator Author

msfroh commented Sep 30, 2023

Unfortunately, since Settings are used throughout the codebase, I can't add it as a unit test. Maybe a dedicated Gradle task?

My preference (partly driven by laziness) is just apply the fix as is -- these circular static initializer dependencies are tricky to catch in automated way.

@reta
Copy link
Collaborator

reta commented Oct 1, 2023

My preference (partly driven by laziness) is just apply the fix as is -- these circular static initializer dependencies are tricky to catch in automated way.

This is tricky to test, if JVM hangs we should have a way to terminate it properly by failing the test, not very straightforward since this is a deadlock.

@reta
Copy link
Collaborator

reta commented Oct 1, 2023

@dblock good with that? (skipping the test part)

@dblock dblock merged commit d3bf230 into opensearch-project:main Oct 2, 2023
60 of 61 checks passed
@dblock
Copy link
Member

dblock commented Oct 2, 2023

YOLO I hit merge. Thanks @msfroh and @reta.

@reta reta added the backport 2.x Backport to 2.x branch label Oct 2, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 2, 2023
There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.

Signed-off-by: Michael Froh <froh@amazon.com>
(cherry picked from commit d3bf230)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
rayshrey pushed a commit to rayshrey/OpenSearch that referenced this pull request Oct 3, 2023
There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.

Signed-off-by: Michael Froh <froh@amazon.com>
reta pushed a commit that referenced this pull request Oct 4, 2023
There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.


(cherry picked from commit d3bf230)

Signed-off-by: Michael Froh <froh@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
deshsidd pushed a commit to deshsidd/OpenSearch that referenced this pull request Oct 9, 2023
There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.

Signed-off-by: Michael Froh <froh@amazon.com>
vikasvb90 pushed a commit to vikasvb90/OpenSearch that referenced this pull request Oct 10, 2023
There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.

Signed-off-by: Michael Froh <froh@amazon.com>
shiv0408 pushed a commit to Gaurav614/OpenSearch that referenced this pull request Apr 25, 2024
There was a weird circular class-loading dependency between Settings and
Settings.Builder that could result in ClassLoader deadlock if multiple
threads trigger class-loading of Settings at the same time.

Signed-off-by: Michael Froh <froh@amazon.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch bug Something isn't working Clients Clients within the Core repository such as High level Rest client and low level client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Parts of Rest High-Level Client not thread-safe
3 participants