Skip to content

Commit

Permalink
Merge pull request #965 from rkhmelichek/master
Browse files Browse the repository at this point in the history
Fix deadlock waiting on docker log pattern to match
  • Loading branch information
rhuss committed Apr 3, 2018
2 parents 5bad31e + 6e6aecf commit 6afcb82
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions src/main/java/io/fabric8/maven/docker/access/log/LogRequestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public class LogRequestor extends Thread implements LogGetHandle {

private final UrlBuilder urlBuilder;

// Lock for synchronizing closing of requests
private final Object lock = new Object();

/**
* Create a helper object for requesting log entries synchronously ({@link #fetchLogs()}) or asynchronously ({@link #start()}.
*
Expand All @@ -86,10 +83,10 @@ public void fetchLogs() {
try {
callback.open();
this.request = getLogRequest(false);
final HttpResponse respone = client.execute(request);
parseResponse(respone);
final HttpResponse response = client.execute(request);
parseResponse(response);
} catch (LogCallback.DoneException e) {
finish();
// Signifies we're finished with the log stream.
} catch (IOException exp) {
callback.error(exp.getMessage());
} finally {
Expand All @@ -99,20 +96,17 @@ public void fetchLogs() {

// Fetch log asynchronously as stream and follow stream
public void run() {
synchronized (lock) {
try {
callback.open();

this.request = getLogRequest(true);
final HttpResponse response = client.execute(request);
parseResponse(response);
} catch (LogCallback.DoneException e) {
finish();
} catch (IOException e) {
callback.error("IO Error while requesting logs: " + e + " " + Thread.currentThread().getName());
} finally {
callback.close();
}
try {
callback.open();
this.request = getLogRequest(true);
final HttpResponse response = client.execute(request);
parseResponse(response);
} catch (LogCallback.DoneException e) {
// Signifies we're finished with the log stream.
} catch (IOException e) {
callback.error("IO Error while requesting logs: " + e + " " + Thread.currentThread().getName());
} finally {
callback.close();
}
}

Expand Down Expand Up @@ -186,18 +180,12 @@ private void parseResponse(HttpResponse response) throws LogCallback.DoneExcepti
throw new LogCallback.DoneException();
}

final InputStream is = response.getEntity().getContent();

try {
try (InputStream is = response.getEntity().getContent()) {
while (true) {
if (!readStreamFrame(is)) {
return;
}
}
} finally {
if ((is != null) && (is.available() > 0)) {
is.close();
}
}
}

Expand All @@ -219,11 +207,9 @@ private HttpUriRequest getLogRequest(boolean follow) {

@Override
public void finish() {
synchronized (lock) {
if (request != null) {
request.abort();
request = null;
}
if (request != null) {
request.abort();
request = null;
}
}

Expand Down

0 comments on commit 6afcb82

Please sign in to comment.