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

[FEATURE REQ] Prevent KeyVault refresh Timer from blocking application termination #19978

Closed
2 tasks done
jwillebrands opened this issue Mar 19, 2021 · 5 comments
Closed
2 tasks done
Assignees
Labels
azure-spring All azure-spring related issues azure-spring-keyvault Spring keyvault related issues. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Milestone

Comments

@jwillebrands
Copy link

jwillebrands commented Mar 19, 2021

Is your feature request related to a problem? Please describe.
We've recently noticed our Spring applications hanging around in a failed state after an unhandled exception tearing down the SpringApplication, without terminating properly. We've traced this back to a change introducing a dependency on azure-spring-boot-starter-keyvault-secrets to sync secrets from Azure KeyVault. Further investigation shows that, when a refreshInterval is configured, the KeyVaultOperation class uses java.util.Timer to set up a task to refresh the secrets.

As stated in the docs, the task execution thread used by Timer does not run as a daemon thread:

By default, the task execution thread does not run as a daemon thread, so it is capable of keeping an application from terminating.

The result is that we see applications being kept alive by this timer thread, despite everything else being torn down. I had considered filing this as a bug, but I'm not sure if this is intentional. We don't see it as a valid use case.

Describe the solution you'd like
Use a daemon thread for the refresh timer tasks. E.g. by creating new Timer objects in KeyVaultOperation setting the daemon flag to true: https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#Timer(boolean)

Describe alternatives you've considered
There are a couple of options that can be implemented instead:

  • If the current behavior is intentional, or changing it is undesirable, the daemon flag could be added to KeyVaultProperties to make it configurable for the consumer.
  • Register for one of the available shutdown hooks to manually cancel() the timer.
  • Should the non-daemon version be kept unchanged, this should be clearly documented.

Additional context
Related artifact: azure-spring-boot-starter-keyvault-secrets
Observed on version 3.1.0

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Description Added
  • Expected solution specified
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 19, 2021
@yiliuTo yiliuTo self-assigned this Mar 22, 2021
@yiliuTo yiliuTo added azure-spring All azure-spring related issues azure-spring-keyvault Spring keyvault related issues. Client This issue points to a problem in the data-plane of the library. feature-request This issue requires a new behavior in the product in order be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 22, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 22, 2021
@yiliuTo
Copy link
Member

yiliuTo commented Mar 22, 2021

Thanks for your suggestions, we will look into this.

@yiliuTo
Copy link
Member

yiliuTo commented Mar 24, 2021

Hi @jwillebrands , the pr to make Timer task run as a daemon thread has been merged. You can wait for our next release of 3.4.0 for the fix.

@jwillebrands
Copy link
Author

Will keep an eye on the PR and we'll look out for the next release. Thanks for picking this up so quickly.

@backwind1233
Copy link
Contributor

#20014

@yiliuTo
Copy link
Member

yiliuTo commented Apr 26, 2021

Hi @jwillebrands , now 3.4.0 has been released and I will close this issue.

@yiliuTo yiliuTo closed this as completed Apr 26, 2021
@chenrujun chenrujun added this to the [2021] April milestone Apr 28, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring All azure-spring related issues azure-spring-keyvault Spring keyvault related issues. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

No branches or pull requests

4 participants