Skip to content

Commit e137293

Browse files
committed
Fix "docker-java-stream" thread stuck at UnixDomainSocket.recv() (OkHttp transport) (#1475)
Prevent unnecessary recurring calls of `recv()` on UNIX socket, which sometimes results in blocking read and causes hanging of "docker-java-stream" thread.
1 parent 33d4259 commit e137293

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/UnixDomainSocket.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,12 @@ class UnixSocketInputStream extends InputStream {
232232
public int read(byte[] bytesEntry, int off, int len) throws IOException {
233233
try {
234234
if (off > 0) {
235-
int bytes = 0;
236-
int remainingLength = len;
237-
int size;
238235
byte[] data = new byte[(len < 10240) ? len : 10240];
239-
do {
240-
size = recv(fd, data, (remainingLength < 10240) ? remainingLength : 10240, 0);
241-
if (size > 0) {
242-
System.arraycopy(data, 0, bytesEntry, off, size);
243-
bytes += size;
244-
off += size;
245-
remainingLength -= size;
246-
}
247-
} while ((remainingLength > 0) && (size > 0));
248-
return bytes;
236+
int size = recv(fd, data, (len < 10240) ? len : 10240, 0);
237+
if (size > 0) {
238+
System.arraycopy(data, 0, bytesEntry, off, size);
239+
}
240+
return size;
249241
} else {
250242
return recv(fd, bytesEntry, len, 0);
251243
}

0 commit comments

Comments
 (0)