Skip to content

Commit e47344f

Browse files
committed
Try to workaround NIO bug http://bugs.sun.com/view_bug.do?bug_id=5103988 with JDK 5
1 parent a40b88f commit e47344f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/main/java/com/ning/http/multipart/MultipartBody.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,30 @@ private long handleFilePart(WritableByteChannel target, FilePart filePart) throw
453453
long nWrite = 0;
454454
synchronized (fc) {
455455
while (fileLength != l) {
456-
nWrite = fc.transferTo(fileLength, l, target);
457-
if (nWrite == 0 ) {
458-
logger.info("Waiting for writing...");
459-
try {
460-
fc.wait(1000);
461-
} catch (InterruptedException e) {
462-
logger.trace(e.getMessage(), e);
456+
try {
457+
nWrite = fc.transferTo(fileLength, l, target);
458+
if (nWrite == 0) {
459+
logger.info("Waiting for writing...");
460+
try {
461+
fc.wait(1000);
462+
} catch (InterruptedException e) {
463+
logger.trace(e.getMessage(), e);
464+
}
465+
}
466+
} catch (IOException ex) {
467+
String message = ex.getMessage();
468+
469+
// http://bugs.sun.com/view_bug.do?bug_id=5103988
470+
if (message != null && message.equalsIgnoreCase("Resource temporarily unavailable")) {
471+
try {
472+
fc.wait(1000);
473+
} catch (InterruptedException e) {
474+
logger.trace(e.getMessage(), e);
475+
}
476+
logger.warn("Experiencing NIO issue http://bugs.sun.com/view_bug.do?bug_id=5103988. Retrying");
477+
continue;
478+
} else {
479+
throw ex;
463480
}
464481
}
465482
fileLength += nWrite;

0 commit comments

Comments
 (0)