From 563a973388dd888b26452fbc1559fdb3b24d52d4 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 27 Nov 2019 21:40:48 +0100 Subject: [PATCH] [DockerRunner] destroyOldContainers: normalize the container name The docker api returns each name with a `/` prefix. In order to not interfere with pending compiles, the deletion process has to acquire an internal lock on the container. The LockManager uses the plain container name without the slash: `project-xxx`. Signed-off-by: Jakob Ackermann --- services/clsi/app/js/DockerRunner.js | 3 +++ services/clsi/test/unit/js/DockerRunnerTests.js | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/services/clsi/app/js/DockerRunner.js b/services/clsi/app/js/DockerRunner.js index fd7fc317ff..3f90c81123 100644 --- a/services/clsi/app/js/DockerRunner.js +++ b/services/clsi/app/js/DockerRunner.js @@ -632,6 +632,9 @@ module.exports = DockerRunner = { ttl ) { if (name.slice(0, 9) === '/project-' && ttl <= 0) { + // strip the / prefix + // the LockManager uses the plain container name + name = name.slice(1) return jobs.push(cb => DockerRunner.destroyContainer(name, id, false, () => cb()) ) diff --git a/services/clsi/test/unit/js/DockerRunnerTests.js b/services/clsi/test/unit/js/DockerRunnerTests.js index 83992833f3..d41ee3f7f1 100644 --- a/services/clsi/test/unit/js/DockerRunnerTests.js +++ b/services/clsi/test/unit/js/DockerRunnerTests.js @@ -630,19 +630,19 @@ describe('DockerRunner', function() { it('should destroy old containers', function() { this.DockerRunner.destroyContainer.callCount.should.equal(1) return this.DockerRunner.destroyContainer - .calledWith('/project-old-container-name', 'old-container-id') + .calledWith('project-old-container-name', 'old-container-id') .should.equal(true) }) it('should not destroy new containers', function() { return this.DockerRunner.destroyContainer - .calledWith('/project-new-container-name', 'new-container-id') + .calledWith('project-new-container-name', 'new-container-id') .should.equal(false) }) it('should not destroy non-project containers', function() { return this.DockerRunner.destroyContainer - .calledWith('/totally-not-a-project-container', 'some-random-id') + .calledWith('totally-not-a-project-container', 'some-random-id') .should.equal(false) })