Skip to content

Commit f9310ea

Browse files
committed
Fix some synchronization issues that allowed more number of containers than the settings permitted
1 parent e220720 commit f9310ea

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.5.0 - 2016-10-06
2+
3+
### Fixed
4+
5+
- Fix some synchronization issues that allowed more number of containers than the settings permitted
6+
17
## 0.4.0 - 2016-09-29
28

39
### Changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121
apply plugin: 'java'
2222

2323
group = 'cd.go.contrib'
24-
version = '0.4'
24+
version = '0.5'
2525
description = 'GoCD Docker Elastic Agents'
2626

2727
// these values that go into plugin.xml

src/main/java/cd/go/contrib/elasticagents/docker/DockerContainers.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ public class DockerContainers implements AgentInstances<DockerContainer> {
4242
@Override
4343
public DockerContainer create(CreateAgentRequest request, PluginSettings settings) throws Exception {
4444
final Integer maxAllowedContainers = settings.getMaxDockerContainers();
45-
doWithLockOnSemaphore(new SetupSemaphore(maxAllowedContainers, instances, semaphore));
46-
47-
if (semaphore.tryAcquire()) {
48-
DockerContainer container = DockerContainer.create(request, settings, docker(settings));
49-
register(container);
50-
return container;
51-
} else {
52-
LOG.info("The number of containers currently running is currently at the maximum permissible limit (" + instances.size() + "). Not creating any more containers.");
53-
return null;
45+
synchronized (instances) {
46+
doWithLockOnSemaphore(new SetupSemaphore(maxAllowedContainers, instances, semaphore));
47+
48+
if (semaphore.tryAcquire()) {
49+
DockerContainer container = DockerContainer.create(request, settings, docker(settings));
50+
register(container);
51+
return container;
52+
} else {
53+
LOG.info("The number of containers currently running is currently at the maximum permissible limit (" + instances.size() + "). Not creating any more containers.");
54+
return null;
55+
}
5456
}
5557
}
5658

@@ -76,7 +78,9 @@ public void run() {
7678
}
7779
});
7880

79-
instances.remove(agentId);
81+
synchronized (instances) {
82+
instances.remove(agentId);
83+
}
8084
}
8185

8286
@Override

0 commit comments

Comments
 (0)