In our application, we have an issue with using KillSwitch, even after shutdown() called we can see mapping operations (they can have blocking calls to DB) continue to execute for a long time.
I was able to reproduce the same behavior in a small code snippet. I would expect to see 10-20 outputs but I see all 100. We can’t change the implementation of functions called in the map operators.
Is there is any way to cancel stream faster?
IntStream intStream = IntStream.range(0, 100);
UniqueKillSwitch run = Source.fromIterator(intStream::iterator)
.map(item -> {
System.out.println(item);
Thread.sleep(100);
return item;
})
.viaMat(KillSwitches.single(), Keep.right())
.toMat(Sink.foreach(item -> {
}), Keep.left())
.run(_actorSystem.getMaterializer());
Thread.sleep(1000);
run.shutdown();