lostluck commented on issue #28142:
URL: https://github.com/apache/beam/issues/28142#issuecomment-1911101091

   The root cause is a subtle thing from the design of the Beam FnAPI protocol, 
but otherwise going to be on an SDK to SDK basis.
   
   Essentially, the data channel and the control channel are coordinated. But 
they are independant. The data could come in before the bundle that processes 
that data, but we need to hold onto it. Similarly, the ProcessBundle request 
could come in earlier, and it needs to wait until the data is ready. Or any 
particular interleaving of the two.
   
   The leak in the code is from that former case, where we're able to pull in 
all the data before ProcessBundle even starts up. Unfortunately, the Data 
channel doesn't know if it may close the Go Channel (elementsChan in the code) 
that sends the elements to the execution layer, until it knows what 
BundleDescriptor is being used so it can see if the Bundle uses Timers or not, 
and if so, how many transforms. In practice, there's likely to only be 2 
streams, One for data, and the other for timers, but per the protocol, it could 
be arbitrary, so the SDK can't make an assumptions.
   
   So the flow causing the leak is:
   See Data for an unseen instruction. 
   Create and cache a elementChan in the read loop.
   Get all the data.
   Marks off how many "is-last" signals we see. (Once we have all the IsLasts, 
the read loop never sees a reference to that instruction ever again).
   Receives the ProcessBundle request.
   Know we have everything, close the channel, so the ProcessBundle can 
terminate.
   
   But the read loop never "learns" that the data is complete and it can evict 
that reader from its cache, since the read loop never sees the instructionID 
again.
   
   PubSub ends up triggering this behavior because outside of backlog catch up, 
each bundle is for a single element, so this causes a great deal of readers in 
the cache.
   
   I should have a PR shortly.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to