cweld510 opened a new pull request #227:
URL: https://github.com/apache/httpcomponents-core/pull/227


   This change addresses a race condition I’ve observed when executing HTTP 
calls using a `ReactiveEntityProducer` and a `ReactiveResponseConsumer`. If not 
all dependencies have been set on the future owned by 
`InternalAbstractHttpAsyncClient` by the time 
`ReactiveResponseConsumer.streamEnd` is called, calling 
`ComplexFuture.setDependency` will throw an `InterruptedIOException` because 
the future has already been successfully completed. Eventually, 
`ReactiveDataConsumer.failed` will be called. As long as 
`ReactiveDataConsumer.flushToSubscriber` was not called between setting 
`completed = true` in `streamEnd` and setting `exception = cause` in `failed`, 
the next invocation of `flushToSubscriber` will throw an exception to the 
subscriber because error messages are published first. I’ve attached a thread 
dump to help explain: 
   
[threads_report.txt](https://github.com/apache/httpcomponents-core/files/5442119/threads_report.txt)
   
   My proposed change causes `ReactiveDataConsumer.failed` to do nothing if the 
consumer has already been set as `complete` (i.e. by 
`ReactiveResponseConsumer.streamEnd`.) This change is consistent with Java’s 
CompletableFuture class, as well as the ComplexFuture and BasicFuture classes 
in the apache-httpcomponents library--in these classes, calling `failed` after 
the object has been marked `complete` is a no-op. It guards against the race 
condition I described by guaranteeing that calling 
`ReactiveDataConsumer.failed` after calling 
`ReactiveResponseConsumer.streamEnd` on the same object does nothing.
   
   Is this the best change to make? I considered some other possible changes, 
such as not calling `dependency.cancel` in `ComplexFuture.setDependency` if the 
future has already completed successfully, but this one seemed to be the most 
straightforward.
   
   Thanks! I can explain more if needed.
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to