Document how to properly avoid sending a 100-continue response
#279 opened on Sep 12, 2016
Repository metrics
- Stars
- (1,311 stars)
- PR merge metrics
- (Avg merge 1d 10h) (2 merged PRs in 30d)
Description
Issue by jroper Thursday Jul 16, 2015 at 12:23 GMT Originally opened as https://github.com/akka/akka/issues/18013
The following test shows the problem:
implicit val system = ActorSystem()
implicit val mat = ActorMaterializer()
val requested = new AtomicLong()
val cancelled = new CountDownLatch(1)
val sink = Sink.cancelled[String]
val source = Source(List("foo", "bar"))
val sourceAsPublisher = source.runWith(Sink.publisher)
val sinkAsSubscriber = sink.runWith(Source.subscriber[String])
val probedPublisher = new Publisher[String] {
def subscribe(subscriber: Subscriber[_ >: String]) = sourceAsPublisher.subscribe(new Subscriber[String] {
def onError(t: Throwable) = subscriber.onError(t)
def onSubscribe(s: Subscription) = subscriber.onSubscribe(new Subscription {
def cancel() = cancelled.countDown()
def request(n: Long) = requested.addAndGet(n)
})
def onComplete() = subscriber.onComplete()
def onNext(t: String) = subscriber.onNext(t)
})
}
val mappedPublisher = Source(probedPublisher).map(identity).runWith(Sink.publisher[String])
mappedPublisher.subscribe(sinkAsSubscriber)
cancelled.await()
assert(requested.get() == 0, "Requested was " + requested.get())
Since the subscriber at the end of the chain is a cancelled sink, there should never be any requests for anything issued anywhere in the chain, however the assertion fails.
Removing the map fixes the problem, as does feeding the probed publisher directly to a cancelled Sink.
This particularly causes a problem for Play, which depends on the absence of a request from a cancelled Sink resulting in the eventual Netty reactive streams publisher not receiving a request in order to know not to send a 100 continue message.