Await.result(someHttpResponseFuture) never returns.

12 views
Skip to first unread message

Ryan Zhu

unread,
Nov 1, 2018, 3:03:08 PM11/1/18
to finatra-users
Hi guys, I have an finatra endpoint doing something like this:
{
  FuturePool.unboundedPool {
    someLock.lock()
    val response = Await.result(someHttpResponseFuture)
    // Process the response
    someLock.unlock()
  }
}

But when I tested this with multiple clients for some time, the controller hung and stopped waiting for the future and never (at least for hours) returned which caused the service deadlock. What could be wrong here? Please share your advise. Thank you very much.

Christopher Coco

unread,
Nov 6, 2018, 10:25:30 AM11/6/18
to xiangh...@gmail.com, finatr...@googlegroups.com
Hi there!

First of all, you should not await like this on a Finagle Future in production code. Secondly, when you do `Await.result` this can effectively block forever since you are not passing a Duration. Lastly, your code seems to not benefit from being wrapped in the outer FuturePool (admittedly, I can't see the rest of what you're doing). But you have a Future from the HTTP client -- you can just map (or flatMap) your logic to that Future instead of starting an unnecessary FuturePool where you fall into the trap of mistakenly awaiting a Future inside.

See these two references for more information on Futures:

Hope that helps.

Thanks,
-c

--
You received this message because you are subscribed to the Google Groups "finatra-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to finatra-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Zhu

unread,
Nov 6, 2018, 10:50:27 AM11/6/18
to finatra-users
Thanks for the explanation. It's really helpful.
Reply all
Reply to author
Forward
0 new messages