Skip to content

Commit

Permalink
Use tryWithSafeFinallyAndFailureCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed Jan 9, 2018
1 parent 8e5ffa4 commit c1278b8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions core/src/main/scala/org/apache/spark/rpc/netty/NettyRpcEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,14 @@ private[netty] class NettyRpcEnv(

val pipe = Pipe.open()
val source = new FileDownloadChannel(pipe.source())
var exceptionThrown = true
try {
Utils.tryWithSafeFinallyAndFailureCallbacks(block = {
val client = downloadClient(parsedUri.getHost(), parsedUri.getPort())
val callback = new FileDownloadCallback(pipe.sink(), source, client)
client.stream(parsedUri.getPath(), callback)
exceptionThrown = false
} finally {
if (exceptionThrown) {
pipe.sink().close()
source.close()
}
}
})(catchBlock = {
pipe.sink().close()
source.close()
})

source
}
Expand Down

0 comments on commit c1278b8

Please sign in to comment.