Skip to content

Commit f648421

Browse files
committed
Fix potential stuck at UnixDomainSocket.read() (HttpClient transport) (#1475)
Prevent unnecessary recurring calls of `read()` on UNIX socket, which may result in blocking read and cause hanging of "docker-java-stream" thread.
1 parent 9b99a84 commit f648421

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,16 @@ class UnixSocketInputStream extends InputStream {
231231
public int read(byte[] bytesEntry, int off, int len) throws IOException {
232232
try {
233233
if (off > 0) {
234-
int bytes = 0;
235-
int remainingLength = len;
236-
int size;
237234
byte[] data = new byte[(len < 10240) ? len : 10240];
238-
do {
239-
if (!isConnected()) {
240-
return -1;
241-
}
242-
size = UnixDomainSocket.read(fd, data, (remainingLength < 10240) ? remainingLength : 10240);
243-
if (size <= 0) {
244-
return -1;
245-
}
246-
System.arraycopy(data, 0, bytesEntry, off, size);
247-
bytes += size;
248-
off += size;
249-
remainingLength -= size;
250-
} while ((remainingLength > 0) && (size > 0));
251-
return bytes;
235+
if (!isConnected()) {
236+
return -1;
237+
}
238+
int size = UnixDomainSocket.read(fd, data, (len < 10240) ? len : 10240);
239+
if (size <= 0) {
240+
return -1;
241+
}
242+
System.arraycopy(data, 0, bytesEntry, off, size);
243+
return size;
252244
} else {
253245
if (!isConnected()) {
254246
return -1;

0 commit comments

Comments
 (0)