Skip to content

Commit e2d9cfe

Browse files
committed
HTTPClient: Don't attempt to process the client if closed
This state check is not sufficent to know if the request has been sent. If the request has been sent then an error may occur because the ClientHTTPRequest body provider is not resettable. This can result in an exception like (in the case with a single sized body): java.util.NoSuchElementException: No elements remaining: 2 org.threadly.util.ArrayIterator.next (ArrayIterator.java:84) org.threadly.litesockets.protocols.http.request.ClientHTTPRequest.nextBodySection (ClientHTTPRequest.java:65) org.threadly.litesockets.client.http.HTTPClient.process (HTTPClient.java:416) org.threadly.litesockets.client.http.HTTPClient.access$1300 (HTTPClient.java:61) org.threadly.litesockets.client.http.HTTPClient$MainClientProcessor.onClose (HTTPClient.java:595) org.threadly.litesockets.Client.lambda$callClosers$0 (Client.java:276) org.threadly.litesockets.Client.runListener (Client.java:294) org.threadly.litesockets.Client.callClosers (Client.java:273) org.threadly.litesockets.TCPClient.lambda$close$0 (TCPClient.java:173) org.threadly.concurrent.wrapper.KeyDistributedExecutor$TaskQueueWorker.runTask (KeyDistributedExecutor.java:448) org.threadly.concurrent.wrapper.KeyDistributedExecutor$TaskQueueWorker.run (KeyDistributedExecutor.java:502) org.threadly.concurrent.AbstractPriorityScheduler$OneTimeTaskWrapper.runTask (AbstractPriorityScheduler.java:715) org.threadly.concurrent.PriorityScheduler$Worker.executeTasksWhileRunning (PriorityScheduler.java:956) org.threadly.concurrent.PriorityScheduler$Worker.run (PriorityScheduler.java:963) java.lang.Thread.run (Thread.java:834) Since the body may be sourced from an InputStream or other means which can't be retried by the library, retry logic needs to be done at the library user level. This change will instead just communicate the connection close error out so it can be retried there.
1 parent dfcc68d commit e2d9cfe

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

client/src/main/java/org/threadly/litesockets/client/http/HTTPClient.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,8 @@ public void onClose(Client client) {
589589

590590
client.close();
591591
if(hrw != null) {
592-
boolean wasProcessing = hrw.hrp.isProcessing();
593592
hrw.hrp.connectionClosed();
594-
if(! hrw.slf.isDone() && ! wasProcessing) {
595-
process(hrw);
596-
} else {
593+
if(! hrw.slf.isDone()) {
597594
hrw.slf.setFailure(new HTTPParsingException("Did not get complete body!"));
598595
}
599596
}

0 commit comments

Comments
 (0)