Skip to content
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

[Thread-leakage]DruidTaskResolver does not stop poll thread after tranquilizer is closed #303

Open
realAaronWu opened this issue Jul 1, 2019 · 1 comment

Comments

@realAaronWu
Copy link

Every time a new connection is established in IndexService, there is a DruidTaskResolver submitting a runnable to a new thread (poll thread) bind to the connection and periodically check the task running status, but when the beam is closed, the poll runnable cannot be notified and cancled properly. This caused a thread leakage in a long-last running jvm.

@realAaronWu
Copy link
Author

realAaronWu commented Jul 1, 2019

The single-threaded executor does not return a future, so the runnable cannot be stopped when the beam is closed.

pollExecutor.submit(
        new Runnable
        {
          override def run(): Unit = {
            while (!Thread.currentThread().isInterrupted) {
              try {
                val tasksSnapshot: Map[Long, (String, AtomicReference[Addr], Updatable[Addr])] = lock.synchronized {
                  while (timekeeper.now.millis < nextPoll) {
                    val waitMillis = nextPoll - timekeeper.now.millis
                    if (waitMillis > 0) {
                      lock.wait(waitMillis)
                    }
                  }
                  tasks
                }

                val now = timekeeper.now
                val baseWait = now.plus(pollPeriod).millis - now.millis
                val fuzzyWait = (math.max(1 + 0.25 * Random.nextGaussian, 0) * baseWait).toLong
                nextPoll = now.millis + fuzzyWait

                val running = Await.result(indexService.runningTasks())

                log.debug(s"Polled[$indexServiceKey] and found ${running.size} tasks " +
                  s"(${running.count(_._2.isBound)} bound).")

                for ((taskNumber, (taskId, addr, updatable)) <- tasksSnapshot) {
                  val runningHostPort = running.get(taskId)
                  val runningAddr: Addr = runningHostPort.map(_.toAddr).getOrElse(Addr.Neg)
                  if (addr.get() != runningAddr) {
                    log.info(s"Updating location for task[$taskId] (#$taskNumber) to[$runningAddr].")
                    addr.set(runningAddr)
                    updatable.update(runningAddr)
                  }
                }
              }
              catch {
                case NonFatal(e) =>
                  log.warn(e, s"Poll failed, trying again at[${new DateTime(nextPoll)}].")
              }
            }
          }
        }
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant