fix: reuse containers per session#489
Conversation
|
gentle ping! @cutecatfann 🙂 |
cutecatfann
left a comment
There was a problem hiding this comment.
Thanks for the PR and for digging into this issue. Looks like the right start :)
A few things I'd like addressed before merging:
- The
Spec.Image != ""override in longLived() is too broad
if serverConfig.Spec.Image != "" {
return true
}
This forces every container-based server to be long-lived regardless of its LongLived flag. Some servers are intentionally stateless and expect a fresh container per call. The double-checked locking alone already fixes the duplication race (multiple goroutines creating containers for the same key concurrently). Please remove this addition, the existing serverConfig.Spec.LongLived || cp.LongLived logic should continue to control caching behavior, and the race fix ensures that when caching IS enabled, only one container is created.
-
The concurrency test doesn't test the actual code path
TestAcquireClientNoDuplicatesUnderConcurrencymanually reimplements the locking logic inside each goroutine instead of callingcp.AcquireClient(). This means the test would pass even if AcquireClient itself still had the race. Please rewrite it to call the real method (you may need to mock the Docker client / container creation to avoid starting real containers). -
ReleaseClientsForSession can trigger container creation
If a clientGetter was stored in the map but GetClient was never called (container never started), callingkc.Getter.GetClient(context.TODO())inside ReleaseClientsForSession will actually trigger the sync.Once and start a container just to close it -
Minor: context.TODO()
Both ReleaseClientsForSessionand the existing Close() use context.TODO(). For the new code, consider accepting or deriving a proper context so the cleanup calls can be cancelled during gateway shutdown.
cool, i've removed the image check entirely
re wrote the test to use cp.AcquireClient() directly now
let me add a check so we don’t start a container during cleanup
sure 👍🏻 |
What I did
Related issue
Fixes #483
A picture of a cute animal