Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock waiting on docker log pattern to match #965

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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