mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(codeartifact): close the remaining register-vs-reset gap in PerKeyContainerPool (#4447)
Follow-up to #4411, both items raised by hectorvent in that review. ensureReady checked the pool's reset generation before registering its new container in the map, not after: a stopAll() landing in the gap between that check and the registration could still run its own sweep over the map without finding the container (it was not in the map yet), then have the registration land afterward with nothing left to ever stop it, the same leak the generation check was meant to close in the first place. A second variant let a stopAll() land between the sweep and the map clear, wiping the entry stopAll() itself never got the chance to visit. Registering first and only then comparing the generation, removing and stopping locally on a mismatch rather than trusting whatever stopAll() may have already done to the map, closes both: either stopAll()'s own sweep finds the container because the registration already landed, or the registration lands after the sweep and the generation check catches it. stopAndRemove already tolerates a double-stop of the same container (both its stop and remove calls treat "already gone" as success), so there's no failure mode where both paths race to clean up the same one. Also drops VerdaccioSidecarManager's class javadoc reference to the CodeArtifactService repository-record walk that #4411 removed; it was describing something that no longer exists.
This commit is contained in:
1 parent
81e646b86d
commit
3da68ff505
2 files changed
+17
-8
No files matched your search
+15
-6
@@ -76,17 +76,26 @@ public class PerKeyContainerPool {
|
||||
}
|
||||
long startedGeneration = generation.get();
|
||||
StartedContainer started = starter.start();
|
||||
// Registered before checking the generation, not after: checking first and only then
|
||||
// registering leaves a gap between the two where a concurrent stopAll() can run and
|
||||
// see nothing (this container isn't in the map yet) without the generation bump alone
|
||||
// catching it either, since that only tells this call a reset happened, not whether
|
||||
// stopAll()'s own sweep already passed the point where it could have found this
|
||||
// container. Registering first means stopAll() either sees it in the map and stops it,
|
||||
// or runs entirely before this put and gets caught by the generation check below;
|
||||
// there is no window where neither happens.
|
||||
containers.put(key, started);
|
||||
if (generation.get() != startedGeneration) {
|
||||
// A stopAll() ran while this container was being built and could not have seen
|
||||
// it: it was not in the map yet. Stop it now rather than register it, so a reset
|
||||
// racing a first-use does not leave this one running behind.
|
||||
// A stopAll() ran while this container was being built and may have already swept
|
||||
// past this key (its forEach found nothing, since the put above hadn't happened
|
||||
// yet) before clearing the map out from under this registration. Remove and stop
|
||||
// it directly rather than trust the map state, which that same stopAll() may have
|
||||
// already cleared.
|
||||
LOG.warnv("Sidecar pool was reset while starting a container for key {0}; stopping it", key);
|
||||
containers.remove(key);
|
||||
lifecycleManager.stopAndRemove(started.containerId(), null);
|
||||
throw new IllegalStateException("Sidecar pool was reset while starting a container for key " + key);
|
||||
}
|
||||
// Tracked before the health wait, not after: a timeout below must not stop
|
||||
// stopContainer()/stopAll() from ever finding this already-running container again.
|
||||
containers.put(key, started);
|
||||
SidecarHealthHelper.waitForHealth(started.baseUrl(), healthPath);
|
||||
return started.baseUrl();
|
||||
}
|
||||
|
||||
+2
-2
@@ -38,8 +38,8 @@ import java.nio.charset.StandardCharsets;
|
||||
* <p>Implements {@link ContainerTeardown} rather than observing {@code ShutdownEvent} directly:
|
||||
* {@code ContainerTeardowns.stopAll} already runs every implementation both at process shutdown
|
||||
* and on {@code /state/reset}/{@code /state/nuke}, so this is what actually stops every
|
||||
* repository's container on reset, not the generic {@code CodeArtifactService} repository-record
|
||||
* walk, which only knows about repositories that still exist in storage.
|
||||
* repository's container on reset, driven by what {@link #pool} is really tracking rather than by
|
||||
* which repository records still exist in storage.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class VerdaccioSidecarManager implements RepositorySidecarManager, ContainerTeardown {
|
||||
|
||||
Reference in new issue
Block a user