Sending an 2xx 'early' response before end of request was received


(Mark Hammons) #1

Hi, I’m receiving this warning on an upload path I implemented:

2018-10-07 19:01:32,090 [warn] a.a.ActorSystemImpl - Sending an 2xx 'early' response before end of request was received... Note that the connection will be closed after this response. Also, many clients will not read early responses! Consider only issuing this response after the request data has been completely read!

This is the definition of the upload path:

//bodyparser definition
  def streamingUploader(experimentName: ExperimentName,
                        aid: String,
                        group: String,
                        fileName: String) = BodyParser { implicit req =>
    val path = aid match {
      case "0" => (IRODSPath(experimentName) / group / fileName).throwFault
      case n   => ???
    }

    val expInfo = pm.tryGetExperimentStubByName(experimentName)

    val auth = PTryT(expInfo).flatMapF { exp =>
      authModule.forceUser(OwnedBy(exp.owner.userID, exp.owningTeam), Write)
    }

    val future = auth
      .flatMapF { _ =>
        logger.info(s"creating directories for $path")
        path.getParent.mkDirs()
      }
      .map { _ =>
        path
          .getSink(overwriteExisting = true)
          .addAttributes(Attributes.inputBuffer(initial = 16, max = 64))
      }
      .map { iSink =>
        logger.info(s"creating accumulator for $path")
        Accumulator(iSink)
          .map {
            case PFailure(f) =>
              Left(InternalServerError(f.faultTrace.mkString("\n")))
            case PSuccess(bs) =>
              logger.info(s"done")
              Right(bs)
          }
      }
      .leftMap { f =>
        logger.error(f.faultTrace.mkString("\n"))
        //todo: create a fault handler spec, and get the appropriate response with it
        Accumulator.done(Left(InternalServerError(f.faultTrace.mkString("\n"))))
      }
      .fold(identity, identity)

    Await.result(future, 3.minutes)
  }

//path definition
  def upload(experimentName: ExperimentName,
             aid: String,
             group: String,
             filename: String) =
    PAction(streamingUploader(experimentName, aid, group, filename)) {
      request =>
        Future.successful(
          PSuccess(Ok(s"${request.body._2};${request.body._1}")))
    }

Any idea why i’m getting this early response warning?

edit: just a bit of clarification; PAction is an Action wrapper I defined that takes a Future[Either[Fault, Result]]]. It just handles bridging that result type to the Result type that an action or a Future[Result] that an Action.async requires.