Skip to content

lerna-http: Substream Source(EntitySource) cannot be materialized more than once が発生しアクセスログのリクエストボディが確認できないことがある #87

@negokaz

Description

@negokaz

ログ出力内容:

WARN Failed to get the request body  java.lang.IllegalStateException: Substream Source(EntitySource) cannot be materialized more than once
    at akka.stream.impl.fusing.SubSource$$anon$11.createMaterializedTwiceException(StreamOfStreams.scala:846)
    at akka.stream.impl.fusing.SubSource$$anon$11.<init>(StreamOfStreams.scala:816)
    at akka.stream.impl.fusing.SubSource.createLogic(StreamOfStreams.scala:812)
    at akka.stream.stage.GraphStage.createLogicAndMaterializedValue(GraphStage.scala:106)
    at akka.stream.stage.GraphStageWithMaterializedValue.createLogicAndMaterializedValue(GraphStage.scala:50)
    at akka.stream.impl.GraphStageIsland.materializeAtomic(PhasedFusingActorMaterializer.scala:705)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:503)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:452)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:444)
    at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:746)
    at akka.stream.scaladsl.Source.runWith(Source.scala:118)
    at akka.stream.scaladsl.Source.runFold(Source.scala:132)
    at akka.http.scaladsl.unmarshalling.PredefinedFromEntityUnmarshallers.$anonfun$byteStringUnmarshaller$3(PredefinedFromEntityUnmarshallers.scala:16)
    at akka.http.scaladsl.unmarshalling.Unmarshaller$$anon$1.apply(Unmarshaller.scala:58)
    at akka.http.scaladsl.unmarshalling.Unmarshaller$EnhancedUnmarshaller$.$anonfun$mapWithInput$3(Unmarshaller.scala:93)
    at akka.http.scaladsl.unmarshalling.Unmarshaller$$anon$1.apply(Unmarshaller.scala:58)
    at akka.http.scaladsl.unmarshalling.LowerPriorityGenericUnmarshallers.$anonfun$messageUnmarshallerFromEntityUnmarshaller$3(GenericUnmarshallers.scala:25)
    at akka.http.scaladsl.unmarshalling.Unmarshaller$$anon$1.apply(Unmarshaller.scala:58)
    at akka.http.scaladsl.unmarshalling.Unmarshal.to(Unmarshal.scala:25)
    at lerna.http.directives.RequestLogDirective.$anonfun$logRequestResultDirective$4(RequestLogDirective.scala:33)
    at akka.http.scaladsl.util.FastFuture$.$anonfun$map$1(FastFuture.scala:22)
    at akka.http.scaladsl.util.FastFuture$.strictTransform$1(FastFuture.scala:40)
    at akka.http.scaladsl.util.FastFuture$.$anonfun$transformWith$3(FastFuture.scala:50)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:448)
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:63)
    at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:100)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
    at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:100)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:49)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:48)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

アクセスログ出力内容(一部抜粋):

200 OK, ResponseHeaders: [], RequestBody: HttpEntity.Default(application/json,394 bytes total), ResponseBody: {}

関連情報:

リクエストボディがチャンクに分割され、当該エラーが発生することがあるとのこと。
toStrictEntity で一度リクエストボディをメモリ上にバッファリングすることで問題を回避できる。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions