Properly wait for entire result in JettyClientCall #1101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JettyClientCall.sendRequest()
is randomly reporting error status code responses (e.g. HTTP 401) as 1001 Communication Error.This is occurring, because it is using
org.eclipse.jetty.client.util.InputStreamResponseListener.get()
which is documented to only wait for the header response and not the entire content.InputStreamResponseListener.await()
is documented to wait for the whole request/response cycle to be finished.Using
InputStreamResponseListener.get()
means that it may or may not get the failure information which is handled by a separate thread and latch. In addition to this problem,JettyClientCall
is incorrectly returning a 1001 error when it catchesExecutionException
.InputStreamResponseListener.get()
is throwing this exception even if there is simply an HTTP error (300+ HTTP status codes). It could be argued that this is incorrect behavior on Jetty's part. It just so happens that sinceInputStreamResponseListener.get()
is used, on an HTTP error code case, many times the code beats the resultLatch in getting the header response and the exception is not thrown. In some cases, the failure gets recorded in time (in a separate thread) resulting in theInputStreamResponseListener.get()
to throwExecutionException
.In summary, anytime there is a failure HTTP status code on a call, there is a random chance for this to fail with 1001 Communication Error instead of the correct HTTP status code.
The fix includes using
InputStreamResponseListener.await()
instead ofInputStreamResponseListener.get()
to properly wait for the entire request/response cycle, and remove the catch forExecutionException
which was incorrectly setting theStatus
to 1001 in these cases. Note,InputStreamResponseListener.await()
does not throwExecutionException
.NOTE: I did not see any Jetty extension related unit tests to contribute to. If there are, and I just missed them, please point them out to me.