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")
}
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.