Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
}
}
} {
closeFile()
try {
inputStream.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this inputStream is passed from outside, like process.getInputStream in ExecutorRunner, so I don't think we should close the inputStream here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,you are right.
But this function is only used in ExecutorRunner, also if an exception occurs within this function,this will ensure the inputStream is closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The another reason is that this function runs in another thread

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be closed here, because the lifecycle of this stream is outside of this class. In practice, the streams used with this class are closed on error anyway.

Copy link
Contributor Author

@10110346 10110346 Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred to DriverRunner:
DriverRunner-->runDriver-->redirectStream-->copyStream, the inputStream is closed in copyStream.

} finally {
closeFile()
}
}
} catch {
case e: Exception =>
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
Random.nextBytes(bytes)

val os = new ByteArrayOutputStream()
Utils.copyStream(new ByteArrayInputStream(bytes), os)
Utils.copyStream(new ByteArrayInputStream(bytes), os, true)

assert(os.toByteArray.toList.equals(bytes.toList))
}
Expand Down Expand Up @@ -488,7 +488,7 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {

test("resolveURIs with multiple paths") {
def assertResolves(before: String, after: String): Unit = {
assume(before.split(",").length > 1)
assume(before.split(",").length >= 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, why do we fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running UtilsSuite, the following warning occurred:

Test Canceled: 1 was not greater than 1
org.scalatest.exceptions.TestCanceledException: 1 was not greater than 1
at org.scalatest.Assertions$class.newTestCanceledException(Assertions.scala:511)
at org.scalatest.FunSuite.newTestCanceledException(FunSuite.scala:1555)
at org.scalatest.Assertions$AssertionsHelper.macroAssume(Assertions.scala:481)
at org.apache.spark.util.UtilsSuite$$anonfun$19.assertResolves$2(UtilsSuite.scala:491)
at org.apache.spark.util.UtilsSuite$$anonfun$19.apply$mcV$sp(UtilsSuite.scala:512)
at org.apache.spark.util.UtilsSuite$$anonfun$19.apply(UtilsSuite.scala:489)
at org.apache.spark.util.UtilsSuite$$anonfun$19.apply(UtilsSuite.scala:489)

def resolve(uri: String): String = Utils.resolveURIs(uri)
assert(resolve(before) === after)
assert(resolve(after) === after)
Expand Down