Skip to content

[SPARK-11572] Process outstanding requests after seeing stop flag #9723

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
wants to merge 5 commits into from
Closed
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 @@ -56,22 +56,30 @@ private[spark] abstract class AsynchronousListenerBus[L <: AnyRef, E](name: Stri

// A counter that represents the number of events produced and consumed in the queue
private val eventLock = new Semaphore(0)
// limit on the number of events to process before exiting. -1 means no limit
private var eventLimit = -1

private val listenerThread = new Thread(name) {
setDaemon(true)
override def run(): Unit = Utils.tryOrStopSparkContext(sparkContext) {
while (true) {
while (eventLimit != 0) {
eventLock.acquire()
self.synchronized {
processingEvent = true
}
try {
if (stopped.get()) {
// Get out of the while loop and shutdown the daemon thread
return
eventLimit = eventQueue.size
if (eventLimit == 0) {
// Get out of the while loop and shutdown the daemon thread
return
}
}
val event = eventQueue.poll
assert(event != null, "event queue was empty but the listener bus was not stopped")
if (eventLimit > 0) {
eventLimit-=1
}
postToAll(event)
} finally {
self.synchronized {
Expand Down