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

InterProcessMutex is not releasing when called inside a future's onSuccess function. #285

Open
ibanner56 opened this issue Sep 17, 2014 · 1 comment

Comments

@ibanner56
Copy link

We're trying to set up a lock for our Zookeeper operations, but when we attempt to call the release function, the entire application simply hangs on the call to release (that is, it prints the 'releasing lock' line, but not the 'lock released' line).

  get(byName) { request =>
    val topologyPromise = new Promise[ResponseBuilder]
    val topologyName = request.routeParams("name")
    val client = zkService.getCuratorClient
    val lock = new InterProcessMutex(client, s"${Config.ZOOKEEPER_APP_PATH}/locks/${topologyName.split("-")(0)}")
    if(lock.acquire(5, TimeUnit.SECONDS)){
      topologyService.getTopologyInfo(topologyName).onSuccess({ topology =>
        log.info("releasing lock")
        lock.release()
        log.info("lock released")
        topologyPromise.setValue(render.json(AppResponse(data = topology)))
      }).onFailure({ t: Throwable =>
        log.info(t.getMessage)
        lock.release()
        client.close()
        topologyPromise.setException(t)
      })
      }
    }
    else {
      log.info("No lock")
      topologyPromise.setValue(render.status(409).json(AppResponse(409, "Unable to acquire lock")))
    }

    topologyPromise
  }

If we use an await on the future, the release does not hang and releases correctly.

      try {
        val topology = Await.result(topologyService.getTopologyInfo(topologyName), Duration.fromMilliseconds(1000))
        topologyPromise.setValue(render.json(AppResponse(data = topology)))
      } catch { case ex: Exception =>
        topologyPromise.setException(ex)
      } finally {
        log.info("releasing lock")
        lock.release()
        log.info("lock released")
      }
@ibanner56
Copy link
Author

I should mention that the onSuccess function _is_ running in the same thread as the acquire command - we initially tried to release the lock inside of a flatMap and received the error for trying to release from a thread that didn't own the lock.

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