Skip to content

Commit c1278b8

Browse files
committed
Use tryWithSafeFinallyAndFailureCallbacks
1 parent 8e5ffa4 commit c1278b8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

core/src/main/scala/org/apache/spark/rpc/netty/NettyRpcEnv.scala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,14 @@ private[netty] class NettyRpcEnv(
332332

333333
val pipe = Pipe.open()
334334
val source = new FileDownloadChannel(pipe.source())
335-
var exceptionThrown = true
336-
try {
335+
Utils.tryWithSafeFinallyAndFailureCallbacks(block = {
337336
val client = downloadClient(parsedUri.getHost(), parsedUri.getPort())
338337
val callback = new FileDownloadCallback(pipe.sink(), source, client)
339338
client.stream(parsedUri.getPath(), callback)
340-
exceptionThrown = false
341-
} finally {
342-
if (exceptionThrown) {
343-
pipe.sink().close()
344-
source.close()
345-
}
346-
}
339+
})(catchBlock = {
340+
pipe.sink().close()
341+
source.close()
342+
})
347343

348344
source
349345
}

0 commit comments

Comments
 (0)