To clarify, this is not a bug in akka. The issue is there are inflight 
futures that must be accounted for. To summarize you need to keep track of 
your inflight operations (futures) and override onUpstreamFinish in the 
InHandler, for example:

override def onUpstreamFinish(): Unit = {
  if (inflight == 0) {
    complete(out)
  } else {
    // there are still items in progress, wait and we'll complete the out port 
in future callback
  }
}


Then in my getAsyncCallback

if (inflight == 0) {
  if (isClosed(in)) {
    complete(out)
  }
}


Andrew

On Friday, December 16, 2016 at 7:44:12 AM UTC-7, sub...@gmail.com wrote:

> Hi,
>
> I'm seeing an issue where the graph completes while there is still data in 
> one of the flows. The last element emitted by the source enters a custom 
> GraphStageLogic flow, where it is sent to a function that returns a Future. 
> That Future has a callback which invokes getAsyncCallback and then 
> push(out). For the last element, the Future callback fires (pushCallback
> .invoke(xml)) but the AsyncCallback is never invoked and the graph stops.
>
> For more context, this is what I have going on inside the GraphStageLogic:
>
> val s3ListBucket: Source[ByteString, NotUsed] =
>   s3Client.listBucket(bucket, Some(currentPrefix), maxKeys, nextMarker)
>
> val bucketListingXml: Future[String] = s3ListBucket
>   .map(_.utf8String)
>   .runWith(Sink.seq)(materializer)
>   .map(_.mkString)(materializer.executionContext)
>
>
>       bucketListingXml.foreach {
>         xml =>
>
>           println(s"This gets called. prefix $currentPrefix")
>
> pushCallback.invoke(xml)
> }(materializer.executionContext)
>
>
> And the callback
>
>
> val pushCallback = getAsyncCallback[String] { xml =>
>   log.info(s"This is never called for last element in graph!")
>   push(out, xml)
> }
>
>
> I don't see any errors and this issue consistently occurs on the last 
> element. Thanks
>
> Andrew
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to