2

it seems like reacitvemongo enumerators are not handling exceptions correctly. The code below consumes an enumerator ( returned by reactivemongo driver) to create a list, the problem here is that when there is an exception inside fold function the request hangs and the browser don't get a response at all ( the loader spins infinitely)

def specialTalks() = AdminAction.async {
implicit request => {
  val query = Json.obj(("status" -> 3))
  val res = talks.find(query).sort(Json.obj(("title" -> 1))).cursor[JsObject]
    .enumerate() |>>> Iteratee.fold[JsObject, List[JsObject]](List[JsObject]())((theList, aTalk) => {
    // an exception may happen here
    if (((aTalk \ "hex").as[String]).length == 24)
      theList :+ aTalk
    else
      theList
  }).map(l => {
    Ok(Json.toJson(Json.obj(("talks" -> l))))
  })
  res.recover({case _ => InternalServerError("Not a hex talk")})
}}

It doesn't even recover from the failing execution.

I'm I missing some thing here or it's a bug in reactivemongo enumerator ?

faissalb
  • 1,739
  • 1
  • 12
  • 14

1 Answers1

2

There is a bug on the enumerator returned by Cursor.enumerate() that make it unable to propagate correctly any error that happens when applying the iteratee.

I've sent a pull request to Reactivemongo team to fix this, details can be found here:

https://github.com/ReactiveMongo/ReactiveMongo/pull/191

faissalb
  • 1,739
  • 1
  • 12
  • 14