apache/hadoop · error · IOException
Unexpected return of {} from transferTo()
Error message
Unexpected return of {} from transferTo() What it means
Error "Unexpected return of {} from transferTo()" thrown in apache/hadoop.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketOutputStream.java:234
* Once we move to JAVA SE 7, wait should be moved to correct place.
*/
long start = System.nanoTime();
waitForWritable();
long wait = System.nanoTime();
int nTransfered = (int) fileCh.transferTo(position, count, getChannel());
if (nTransfered == 0) {
//check if end of file is reached.
if (position >= fileCh.size()) {
throw new EOFException("EOF Reached. file size is " + fileCh.size() +
" and " + count + " more bytes left to be " +
"transfered.");
}
//otherwise assume the socket is full.
//waitForWritable(); // see comment above.
} else if (nTransfered < 0) {
throw new IOException("Unexpected return of " + nTransfered +
" from transferTo()");
} else {
position += nTransfered;
count -= nTransfered;
}
long transfer = System.nanoTime();
waitTime += wait - start;
transferTime += transfer - wait;
}
if (waitForWritableTime != null) {
waitForWritableTime.set(waitTime);
}
if (transferToTime != null) {
transferToTime.set(transferTime);
}
}
View on GitHub (pinned to 2add963021)
Solutions
- Check the underlying FileChannel and filesystem for errors; transferTo returning an unexpected count usually indicates an I/O problem or concurrent modification of the file.
- Verify the file size did not change during the transfer and retry the operation.
- Review OS-level limits (sendfile limits) and fall back to stream-based copy if zero-copy transfer is unreliable on this platform.
When it happens
Trigger: Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketOutputStream.java:234 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/b36c0ffc3c5b83f2.
Report an issue: GitHub.