-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-14914][CORE] Fix Resource not closed after using, mostly for unit tests #15618
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
Conversation
Helping script for windows to download dependency and start zinc to support incremental building on windows.
|
Test build #67491 has finished for PR 15618 at commit
|
|
retest this please |
|
Test build #67507 has finished for PR 15618 at commit
|
|
retest this please |
|
Let me take a look into this deeper if some tests constantly fail. |
|
Test build #67516 has finished for PR 15618 at commit
|
|
There are a bunch of methods in Utils which actually nicely apply to this PR.
They also handle exception suppression, etc. |
| serializer.deserializeStream(fileInputStream) | ||
| } catch { | ||
| case e : Throwable => | ||
| fileInputStream.close() |
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.
shouldn't this be in a try {} finally {} instead?
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.
Not here because the stream needs to be open afterwards. I had a similar discussion on the original pr.
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 don't mean having the finally here on this line...
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 am sorry to ask repeatedly but could I please ask how I should change this a little bit more?
I was thinking I should not use finally upon fileInputStream as it should not always be closed at this point or around this point..
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.
Ah, did you mean something like this?
val partitioner = Utils.tryWithSafeFinally[Partitioner] {
val deserializeStream = serializer.deserializeStream(fileInputStream)
Utils.tryWithSafeFinally[Partitioner] {
deserializeStream.readObject[Partitioner]
} {
deserializeStream.close()
}
} {
fileInputStream.close()
}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 I think that's a good idea. Do you need the generic types on the "try" methods, even?
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.
Ah-ha, sure. Let me then try. Thanks for bearing with me.
|
Thanks @mridulm and @felixcheung. Let me try to address your comments. |
|
cc @fuzhouch too (we talked about this via emails). |
|
I just took a look for |
|
@HyukjinKwon So the idea is that you acquire resources required and dont need to track it by wrapping them in Utils.tryWithResource (similar to memory management in jvm). As an example: Even core/src/test/scala/org/apache/spark/FileSuite.scala, core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala, etc change can be modelled the same way. This is essentially analogous to try-with-resources in java. Since you are anyway going through the pain of making all these changes to fix up code, might be a good idea to change it such that future tests will follow the same pattern. |
|
It makes sense to use the Utils methods where possible, sure. |
…r checks in methods
|
Test build #67903 has finished for PR 15618 at commit
|
|
retest this please |
|
Oh wait, it seems the failed test is potentislly related. Will take a look. |
|
Test build #67928 has finished for PR 15618 at commit
|
|
Hm.. @srowen @tdas and @mridulm . I just got rid of the changes in One way I am thinking is, initiate this Otherwise, could I please ask anyone who is familiar with this to make a followup if it is fine? |
|
Test build #68231 has finished for PR 15618 at commit
|
srowen
left a comment
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.
OK perhaps except for one last question.
|
|
||
| override def beforeAll(): Unit = { | ||
| super.beforeAll() | ||
| checkpointDir = Utils.createTempDir("checkpoint") |
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.
This might happen to be OK, but now the dir is not deleted between tests. Is that going to be OK?
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.
Actually, it seems the original codes are already fine in here.. I took a look and ran several tests and it seems now I may understand why @taoli91 tried to fix the codes like this.
It seems somehow the state in ReceiverTracker went wrong on Windows and ended up without closing checkpointDir. It seems the original test was failed[1] due to the issue in ReceiverTracker. So, I think he tried to only create/delete the folder once[2] and ensure stopping ReceivedBlockTracker in ReceiverTracker regardless of the state.
I tested this with manually stopping ReceivedBlockTracker regardless of the state (the original proposal) and it seems fine without the changes in here, MapWithStateSuite.scala[3]. Of course, it is fine with this change[4].
[1]https://ci.appveyor.com/project/spark-test/spark/build/56-F88EDDAF-E576-4787-9530-A4185FC46B1E
[2]https://ci.appveyor.com/project/spark-test/spark/build/57-test-MapWithStateSuite
[3]https://ci.appveyor.com/project/spark-test/spark/build/58-test-MapWithStateSuite
[4]https://ci.appveyor.com/project/spark-test/spark/build/59-test-MapWithStateSuite
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 believe this change is not valid. I will get rid of this. Thank you for pointing this out.
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.
BTW, the reason why [1][2] were failed on Windows (without ensuring stopping ReceivedBlockTracker) seems, the directory, checkpointDir, is being opened so it fails to delete the directory throwing an exception.
|
Test build #68273 has finished for PR 15618 at commit
|
|
LGTM, merging it into master. |
|
I'm going to merge to 2.1 as well to match #15320 |
|
Scratch that; it doesn't merge cleanly. Let's leave it. |
…ts and example ## What changes were proposed in this pull request? This is a follow-up work of apache#15618. Close file source; For any newly created streaming context outside the withContext, explicitly close the context. ## How was this patch tested? Existing unit tests. Author: [email protected] <[email protected]> Closes apache#15818 from wangmiao1981/rtest.
…nit tests ## What changes were proposed in this pull request? Close `FileStreams`, `ZipFiles` etc to release the resources after using. Not closing the resources will cause IO Exception to be raised while deleting temp files. ## How was this patch tested? Existing tests Author: U-FAREAST\tl <[email protected]> Author: hyukjinkwon <[email protected]> Author: Tao LI <[email protected]> Closes apache#15618 from HyukjinKwon/SPARK-14914-1.
…ts and example ## What changes were proposed in this pull request? This is a follow-up work of apache#15618. Close file source; For any newly created streaming context outside the withContext, explicitly close the context. ## How was this patch tested? Existing unit tests. Author: [email protected] <[email protected]> Closes apache#15818 from wangmiao1981/rtest.
What changes were proposed in this pull request?
Close
FileStreams,ZipFilesetc to release the resources after using. Not closing the resources will cause IO Exception to be raised while deleting temp files.How was this patch tested?
Existing tests