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

Multi-threading support with object pool #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Crypt32
Copy link
Collaborator

@Crypt32 Crypt32 commented Dec 5, 2024

This PR contains a potential fix for issue #2.

In short, CertServer property in CertPolicyBase and CertExitBase is not thread-safe and it appears that VerifyRequest and Notify methods are called by CA asynchronously, which results in exception and CA service crash.

I've expressed my concerns about possible fixes that would:

  • not overcomplicate policy and exit module development
  • protect module from resource overconsumption
  • reduce managed/unmanaged resource allocation and cleanup
  • boost performance in multi-threading

This PR comes with a object pool of CertServerModule instances. The idea is inspired by Microsoft CLM policy module. Pool size is fixed and have some limits. Upper size limit is 63. At any given time, no more than 63 threads (or requests) can be processed in parallel. If there are more parallel calls, they are put in queue until any currently running thread finish. Entire pool is pre-created during policy module initialization, so extra resources are allocated only once.

I think it should greatly improve policy module performance over single-threded (with locks on single CertServerModule instance). However, due to the way how previous approach was implemented, it is not possible to fix race condition issue without introducing breaking change. These changes include:

  • CertPolicyBase.VerifyRequest(String, Int32, Int32, Int32) and CertExitBase.Notify(ExitEvents, Int32) methods (that implement required interface) are no longer virtual and do not allow override.
  • Instead, they call new abstract methods CertPolicyBase.VerifyRequest(CertServerModule, PolicyModuleAction, Boolean) and CertExitBase.Notify(CertServerModule, ExitEvents, Int32) respectively, where first parameter provides a thread-safe instance of CertServerModule.

This framework automatically acquire (and wait if necessary) and return object to the pool.

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.

The idea of CertPolicyBase::CertServer is vulnerable to race conditions
1 participant