Skip to content

Commit 2039226

Browse files
author
Stephane Landelle
committed
Port 169051c on master
1 parent 41460f4 commit 2039226

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,18 +579,20 @@ private long writeToTarget(WritableByteChannel target, ByteArrayOutputStream byt
579579
final SocketChannel channel = (SocketChannel) target;
580580
channel.register(selector, SelectionKey.OP_WRITE);
581581

582-
while (written < byteWriter.size() && selector.select() != 0) {
582+
while (written < byteWriter.size()) {
583+
selector.select(1000);
584+
maxSpin++;
583585
final Set<SelectionKey> selectedKeys = selector.selectedKeys();
584586

585587
for (SelectionKey key : selectedKeys) {
586588
if (key.isWritable()) {
587589
written += target.write(message);
590+
maxSpin = 0;
588591
}
589592
}
590-
}
591-
592-
if (written < byteWriter.size()) {
593-
throw new IOException("Unable to write on channel " + target);
593+
if (maxSpin >= 10) {
594+
throw new IOException("Unable to write on channel " + target);
595+
}
594596
}
595597
} finally {
596598
selector.close();

0 commit comments

Comments
 (0)