jetty.project
jetty.project copied to clipboard
Sink.write, Source.demand and Source.read safely reentrant guarantees
Jetty Version 12.0.8
Jetty Environment Any
Java Version Any
Question Are these guarantees actually provided? "Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Callback and a call to this method."
I'm asking because found that ContentCopier uses IteratingCallback and would like to double check that. Thanks!
@scrat98 IteratingCallback and SerializedInvoker are two key mechanisms implemented in Jetty to prevent deep recursion when callback methods again invoke a method. We use these extensively through the code base and do have tests to check we do not deeply recurse.
Typically these mechanism avoid a deep recursion as follows:
- application calls a method like
write(last,buffer,callback)- the write method calls succeeded on the callback
- the callback again calls
write(last,buffer,callback)- the write succeeds, but it is noticed that we are already in the scope of a callback, so succeeded is not called.
- the callback again calls
- the call to succeeded returns and we notice that another operation has now succeeded, so the next succeeded callback is made at this level rather than at the recursed level.
- the callback again calls
write(last,buffer,callback)- the write succeeds, but it is noticed that we are already in the scope of a callback, so succeeded is not called.
- the callback again calls
- etc.
- the write method calls succeeded on the callback
Can this be closed?
Thanks for clarity!