Github user mridulm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16657#discussion_r97056028
  
    --- Diff: 
core/src/main/scala/org/apache/spark/storage/DiskBlockObjectWriter.scala ---
    @@ -206,18 +209,22 @@ private[spark] class DiskBlockObjectWriter(
             streamOpen = false
             closeResources()
           }
    +   } catch {
    +      case e: Exception =>
    +        logError("Uncaught exception while closing file " + file, e)
    +    }
     
    -      val truncateStream = new FileOutputStream(file, true)
    -      try {
    -        truncateStream.getChannel.truncate(committedPosition)
    -        file
    -      } finally {
    -        truncateStream.close()
    -      }
    +    var truncateStream: FileOutputStream = null
    +    try {
    +      truncateStream = new FileOutputStream(file, true)
    +      truncateStream.getChannel.truncate(committedPosition)
    +      file
         } catch {
           case e: Exception =>
             logError("Uncaught exception while reverting partial writes to 
file " + file, e)
             file
    +    } finally {
    +      truncateStream.close()
    --- End diff --
    
    Another option is to use `Utils.tryWithSafeFinally` and do the if block 
with closeResources in the block with truncate in the finally block


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to