Hy!
I have a custom binding the code is exactly this;
val settings = ServerSettings(actorSystem)
val (bind, done) = Http()
.newServerAt("0.0.0.0", 9000)
.connectionSource()
.mapAsyncUnordered(settings.maxConnections) { in =>
var req: Option[HttpRequest] = None
in.handleWith(
Flow[HttpRequest]
.mapAsync(1) { in =>
req = Some(in)
routeGen().flatMap(_(in))
}
.watchTermination()(Keep.right)
).recover {
case ex =>
req.fold {
logger.info("Routing error!", ex)
Done
} { req =>
logger.info(s"Routing error! on ${req.method} ${req.uri}", ex)
Done
}
}
}
.toMat(Sink.ignore)(Keep.both)
.run()
And I get;
2021-10-26 07:27:20 INFO main.AkkaWebserver$ - Routing error!
akka.stream.StreamTcpException: The connection actor has terminated. Stopping now.
This means that the tcp connection is terminating BEFORE I get the chance to “cache” the incoming http request. The maxConnection is 2048, we definitely need to improve our metrics, but it seems that we are way under the limit. Most of our requests end with a 200 or 404 in a 40-300ms range (according to nginx). I think it is some kind of browser cut connection thingy, but I’m generally interested if others saw something like this, or I messed up something, or if there are any tips’n’tricks to improve the above code.