-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-16139][TEST] Add logging functionality for leaked threads in tests #19893
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
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9acbb62
[SPARK-16139][TEST] Add logging functionality for leaked threads in t…
gaborgsomogyi 9058603
Apache license header added
gaborgsomogyi 0d45a5b
Review fix
gaborgsomogyi 1a64209
Review fixes
gaborgsomogyi a35a52f
Review fixes
gaborgsomogyi fe6cd0c
Doc indentation fix
gaborgsomogyi 2b02d45
Review fix
gaborgsomogyi 62cb32b
Documentation added for whitelisted threads
gaborgsomogyi 644ee6a
SparkContext related whitelist entries removed
gaborgsomogyi 3bde33c
Logic extracted into a trait to make it less invasive + SQL related t…
gaborgsomogyi ef58576
Fixing hive related false positives + added whitelisted threads with …
gaborgsomogyi 827b6dc
Scala doc fix
gaborgsomogyi d38a0c6
Scala doc fix
gaborgsomogyi e2da334
Review fix
gaborgsomogyi ef00796
False positive test fix in SQL
gaborgsomogyi f7939fa
Fixing nits
gaborgsomogyi 0851ef2
Review fixes
gaborgsomogyi 87c4852
Review fix
gaborgsomogyi 9c9c6ef
SharedSQLContext explanation added
gaborgsomogyi 56a41df
Turn off default thread audit for hive + SharedSQLContext comment enh…
gaborgsomogyi 68d0f3b
Merge branch 'master' into SPARK-16139
gaborgsomogyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
import org.apache.spark.internal.Logging | ||
|
||
/** | ||
* Thread audit for test suites. | ||
*/ | ||
trait ThreadAudit extends Logging { | ||
|
||
val threadWhiteList = Set( | ||
/** | ||
* Netty related internal threads. | ||
* These are excluded because their lifecycle is handled by the netty itself | ||
* and spark has no explicit effect on them. | ||
*/ | ||
"netty.*", | ||
|
||
/** | ||
* Netty related internal threads. | ||
* A Single-thread singleton EventExecutor inside netty which creates such threads. | ||
* These are excluded because their lifecycle is handled by the netty itself | ||
* and spark has no explicit effect on them. | ||
*/ | ||
"globalEventExecutor.*", | ||
|
||
/** | ||
* Netty related internal threads. | ||
* Checks if a thread is alive periodically and runs a task when a thread dies. | ||
* These are excluded because their lifecycle is handled by the netty itself | ||
* and spark has no explicit effect on them. | ||
*/ | ||
"threadDeathWatcher.*", | ||
|
||
/** | ||
* During [[SparkContext]] creation [[org.apache.spark.rpc.netty.NettyRpcEnv]] | ||
* creates event loops. One is wrapped inside | ||
* [[org.apache.spark.network.server.TransportServer]] | ||
* the other one is inside [[org.apache.spark.network.client.TransportClient]]. | ||
* The thread pools behind shut down asynchronously triggered by [[SparkContext#stop]]. | ||
* Manually checked and all of them stopped properly. | ||
*/ | ||
"rpc-client.*", | ||
"rpc-server.*", | ||
|
||
/** | ||
* During [[SparkContext]] creation BlockManager creates event loops. One is wrapped inside | ||
* [[org.apache.spark.network.server.TransportServer]] | ||
* the other one is inside [[org.apache.spark.network.client.TransportClient]]. | ||
* The thread pools behind shut down asynchronously triggered by [[SparkContext#stop]]. | ||
* Manually checked and all of them stopped properly. | ||
*/ | ||
"shuffle-client.*", | ||
"shuffle-server.*" | ||
) | ||
private var threadNamesSnapshot: Set[String] = Set.empty | ||
|
||
protected def doThreadPreAudit(): Unit = { | ||
threadNamesSnapshot = runningThreadNames() | ||
} | ||
|
||
protected def doThreadPostAudit(): Unit = { | ||
val shortSuiteName = this.getClass.getName.replaceAll("org.apache.spark", "o.a.s") | ||
|
||
if (threadNamesSnapshot.nonEmpty) { | ||
val remainingThreadNames = runningThreadNames().diff(threadNamesSnapshot) | ||
.filterNot { s => threadWhiteList.exists(s.matches(_)) } | ||
if (remainingThreadNames.nonEmpty) { | ||
logWarning(s"\n\n===== POSSIBLE THREAD LEAK IN SUITE $shortSuiteName, " + | ||
s"thread names: ${remainingThreadNames.mkString(", ")} =====\n") | ||
} | ||
} else { | ||
logWarning("\n\n===== THREAD AUDIT POST ACTION CALLED " + | ||
s"WITHOUT PRE ACTION IN SUITE $shortSuiteName =====\n") | ||
} | ||
} | ||
|
||
private def runningThreadNames(): Set[String] = { | ||
Thread.getAllStackTraces.keySet().asScala.map(_.getName).toSet | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was this change about? not shadowing?
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.
Here originally the newly created instance was stored in a local variable which was never saved in member and freed properly. With this change the afterEach method stops it and frees up the resources.