HeartSaVioR commented on a change in pull request #25552: [SPARK-28849][CORE] 
Add a number to control transferTo calls to avoid infinite loop in some 
occasional cases
URL: https://github.com/apache/spark/pull/25552#discussion_r316952694
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/util/Utils.scala
 ##########
 @@ -417,16 +418,19 @@ private[spark] object Utils extends Logging {
       input: FileChannel,
       output: WritableByteChannel,
       startPosition: Long,
-      bytesToCopy: Long): Unit = {
+      bytesToCopy: Long,
+      numTransferToCalls: Int): Unit = {
     val outputInitialState = output match {
       case outputFileChannel: FileChannel =>
         Some((outputFileChannel.position(), outputFileChannel))
       case _ => None
     }
     var count = 0L
+    var num = 0
     // In case transferTo method transferred less data than we have required.
-    while (count < bytesToCopy) {
+    while (count < bytesToCopy && num < numTransferToCalls) {
       count += input.transferTo(count + startPosition, bytesToCopy - count, 
output)
 
 Review comment:
   numTransferToCalls would depend on the size of bytesToCopy so harder to set 
which value makes sense to find the issue and do fail fast. Though `transferTo` 
can return 0 according to javadoc, if it would return 0 continuously (like 100 
times) it sounds an issue to me.
   
   We can also apply exponential wait here when the return value is 0, if it 
turns out calling transferTo right again doesn't help. May helps to avoid 
system usage going mad.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to