[SPARK-22058][CORE]the BufferedInputStream will not be closed if an exception occurs.#19277
[SPARK-22058][CORE]the BufferedInputStream will not be closed if an exception occurs.#19277zuotingbing wants to merge 4 commits intoapache:masterfrom
Conversation
| // Compression codec is encoded as an extension, e.g. app_123.lzf | ||
| // Since we sanitize the app ID to not include periods, it is safe to split on it | ||
| val logName = log.getName.stripSuffix(IN_PROGRESS) | ||
| val codecName: Option[String] = logName.split("\\.").tail.lastOption |
There was a problem hiding this comment.
These two lines don't need to be in the try block. Best to keep it small.
There was a problem hiding this comment.
yes, will fix it. Thanks srowen.
|
|
||
|
|
||
| try { | ||
| val codec = codecName.map { c => |
There was a problem hiding this comment.
Why would here throw an exception?
There was a problem hiding this comment.
Because there can throws an exception with "Codec [$codecName] is not available" in CompressionCodec.createCodec function.
There was a problem hiding this comment.
While we're tightening, this whole body could be
codecName.map { c =>
val codec = codecMap.getOrElseUpdate(c, CompressionCodec.createCodec(new SparkConf, c))
codec.compressedInputStream(in)
}.getOrElse(in)
| val codec = codecName.map { c => | ||
| codecMap.getOrElseUpdate(c, CompressionCodec.createCodec(new SparkConf, c)) | ||
| } | ||
| codec.map(_.compressedInputStream(in)).getOrElse(in) |
There was a problem hiding this comment.
Is it better to move this line val in = new BufferedInputStream(fs.open(log)) to here to solve your problem?
|
I am not sure. If we move this line |
|
Strictly saying, this line |
|
|
||
|
|
||
| try { | ||
| val codec = codecName.map { c => |
There was a problem hiding this comment.
While we're tightening, this whole body could be
codecName.map { c =>
val codec = codecMap.getOrElseUpdate(c, CompressionCodec.createCodec(new SparkConf, c))
codec.compressedInputStream(in)
}.getOrElse(in)
| @@ -351,11 +351,11 @@ private[spark] object EventLoggingListener extends Logging { | |||
| // Since we sanitize the app ID to not include periods, it is safe to split on it | |||
| val logName = log.getName.stripSuffix(IN_PROGRESS) | |||
There was a problem hiding this comment.
Maybe move declaration of in to just before the try
| } | ||
| codec.map(_.compressedInputStream(in)).getOrElse(in) | ||
| } catch { | ||
| case e: Exception => |
There was a problem hiding this comment.
I also note this doesn't handle Throwable, nor does a similar block earlier in the file. In case of say OutOfMemoryError it wouldn't be closed
There was a problem hiding this comment.
yes , but if occurs error , it is of small significance to close the BufferedInputStream.
will fix as you said.
|
@jerryshao if this line |
|
@zuotingbing no, |
| codec.map(_.compressedInputStream(in)).getOrElse(in) | ||
| } catch { | ||
| case e: Exception => | ||
| case e: Throwable => |
There was a problem hiding this comment.
What specific case do we want to catch here?
There was a problem hiding this comment.
srowen 19 hours ago Member
I also note this doesn't handle Throwable, nor does a similar block earlier in the file. In case of say OutOfMemoryError it wouldn't be closed
with srowen's suggest, we could handle everything include exceptions and errors.
|
What other instances of try-catch might need improvement like this? |
|
Test build #3929 has finished for PR 19277 at commit
|
|
Test build #3932 has started for PR 19277 at commit |
|
Test build #3933 has finished for PR 19277 at commit
|
What changes were proposed in this pull request?
EventLoggingListener use
val in = new BufferedInputStream(fs.open(log))and will close it ifcodec.map(_.compressedInputStream(in)).getOrElse(in)occurs an exception .But, if
CompressionCodec.createCodec(new SparkConf, c)throws an exception, the BufferedInputStreaminwill not be closed anymore.How was this patch tested?
exist tests