Skip to content

Core: thread-safe initialization for GoogleAuthManager#16848

Open
vladislav-sidorovich wants to merge 1 commit into
apache:mainfrom
vladislav-sidorovich:google-auth-thread-safe
Open

Core: thread-safe initialization for GoogleAuthManager#16848
vladislav-sidorovich wants to merge 1 commit into
apache:mainfrom
vladislav-sidorovich:google-auth-thread-safe

Conversation

@vladislav-sidorovich

Copy link
Copy Markdown
Contributor

Make initialization for GoogleAuthManager thread-sage.

@github-actions github-actions Bot added the GCP label Jun 17, 2026
@vladislav-sidorovich vladislav-sidorovich changed the title thread-safe initialization for GoogleAuthManager Core: thread-safe initialization for GoogleAuthManager Jun 17, 2026
}

startLatch.countDown();
finishLatch.await(10, TimeUnit.SECONDS);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably should assert the return value of await() is true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% sure about it, let's discuss.

Java doc:

Returns:
true if the count reached zero and false if the waiting time elapsed before the count reached zero

So, in my opinion the test should fail on the verify(spyManager, times(1)) but not on the fact that the wait time > 10 seconds.

What do you think?

Note: actually in other tests in Iceberg it works without isTrue.

}

startLatch.countDown();
finishLatch.await(10, TimeUnit.SECONDS);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
finishLatch.await(10, TimeUnit.SECONDS);
assertThat(finishLatch.await(10, TimeUnit.SECONDS)).isTrue();

GoogleAuthManager spyManager = spy(authManager);
doReturn(credentials)
.when(spyManager)
.loadCredentials(anyBoolean(), any(), anyBoolean(), any(), any());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test probably won't catch the bug you fixed because it returns value quickly? In other words, does this test reliably fail without the fix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the test will fail. I commented the synchronyzed section and run the test. The test failed with the following error:


googleAuthManager.loadCredentials(
    <any boolean>,
    <any>,
    <any boolean>,
    <any>,
    <any>
);
Wanted 1 time:
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.loadCredentials(GoogleAuthManager.java:128)
But was 10 times:
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)

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.

2 participants