Skip to content

Commit

Permalink
Fix deadlock when ryuk does not acknowledge filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hammerl committed Aug 21, 2018
1 parent d2ff073 commit 3cf99b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## UNRELEASED

### Fixed
- Fixed deadlock when registering filters with ryuk container

### Changed

Expand Down
20 changes: 16 additions & 4 deletions core/src/main/java/org/testcontainers/utility/ResourceReaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class ResourceReaper {
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceReaper.class);

private static final List<List<Map.Entry<String, String>>> DEATH_NOTE = new ArrayList<>();
private static final String ACKNOWLEDGMENT = "ACK";

private static ResourceReaper instance;
private final DockerClient dockerClient;
Expand Down Expand Up @@ -144,11 +145,14 @@ public static String start(String hostIpAddress, DockerClient client, boolean wi
out.write('\n');
out.flush();

while (!"ACK".equalsIgnoreCase(in.readLine())) {
boolean isAcknowledged = waitForAcknowledgment(in);
if (isAcknowledged) {
log.debug("Received 'ACK' from Ryuk");
ryukScheduledLatch.countDown();
index++;
} else {
log.debug("Didn't receive 'ACK' from Ryuk. Will retry to send filters.");
}

ryukScheduledLatch.countDown();
index++;
}
}
} catch (IOException e) {
Expand All @@ -169,6 +173,14 @@ public static String start(String hostIpAddress, DockerClient client, boolean wi
return ryukContainerId;
}

private static boolean waitForAcknowledgment(BufferedReader in) throws IOException {
String line = in.readLine();
while (line != null && !ACKNOWLEDGMENT.equalsIgnoreCase(line)) {
line = in.readLine();
}
return ACKNOWLEDGMENT.equalsIgnoreCase(line);
}

public synchronized static ResourceReaper instance() {
if (instance == null) {
instance = new ResourceReaper();
Expand Down

0 comments on commit 3cf99b9

Please sign in to comment.