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

Added timeout for fetching windows keystores #445

Conversation

Hakky54
Copy link
Owner

@Hakky54 Hakky54 commented Jan 20, 2024

No description provided.

@Hakky54 Hakky54 changed the title Added timeout and excluded keystore types for fetching windows keystores Added timeout for fetching windows keystores Jan 21, 2024
Copy link

return keyStore;
})
.thenApply(Optional::of)
.get(500, TimeUnit.MILLISECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

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

The timeout will make the CompletableFuture complete exceptionally with a TimeoutException, but the underlying thread will probably stay blocked.
After multiple calls, it may create a thread leak (supplyAsync uses the ForkJoin pool, which is not limited in the number of threads AFAIR).

If you want more control, you should not use CompletableFuture, but your own thread, and attempt to interrupt it after the timeout. But I am not even sure it would work, because the stacktrace showed that the process was blocked in native code (sun.security.mscapi.CKeyStore.loadKeysOrCertificateChains) and I have no idea if this could be interrupted.

Copy link
Owner Author

@Hakky54 Hakky54 Jan 22, 2024

Choose a reason for hiding this comment

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

Yeah, you might be correct indeed. The underlying thread can still be active...
I will investigate whether the native code can be interrupted or else this PR will not resolve the issue at all.
Thank you for reviewing this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Correcting myself :

The timeout will make the CompletableFuture complete exceptionally with a TimeoutException

this is inaccurate. get(timeout) will throw a TimeoutException if the time is exceeded, but the CompletableFuture will still be not completed.

You could be tempted to do:

   try {
      future.get(timeout);
   } catch (TimeoutException e) {
      future.cancel(true);
   }

The problem is that the "interruptIfRunning" flag is not used by the completable future framework. And the question about the actual effect of interrupting a native method call remains anyway.

@Hakky54 Hakky54 closed this Feb 2, 2024
@Hakky54 Hakky54 deleted the bug-fix/reduce-amount-of-time-to-load-windows-system-keystore-types branch February 2, 2024 09:49
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.

Loading the keystore takes a very long time in some rare cases
2 participants