New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-22058][CORE]the BufferedInputStream will not be closed if an exception occurs. #19277
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines don't need to be in the try block. Best to keep it small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will fix it. Thanks srowen.
try { | ||
val codec = codecName.map { c => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would here throw an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there can throws an exception with "Codec [$codecName] is not available" in CompressionCodec.createCodec
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
try { | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move declaration of in
to just before the try
try { | ||
val codec = codecName.map { c => | ||
codecMap.getOrElseUpdate(c, CompressionCodec.createCodec(new SparkConf, c)) | ||
} | ||
codec.map(_.compressedInputStream(in)).getOrElse(in) | ||
} catch { | ||
case e: Exception => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What specific case do we want to catch here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 BufferedInputStreamin
will not be closed anymore.How was this patch tested?
exist tests