summaryrefslogtreecommitdiffstats
path: root/vespa-http-client
diff options
context:
space:
mode:
authorHaakon Dybdahl <dybdahl@yahoo-inc.com>2016-09-01 12:25:55 +0200
committerHaakon Dybdahl <dybdahl@yahoo-inc.com>2016-09-01 12:25:55 +0200
commita2db4b7f5ffef72236f531baeb9f69176d39a20d (patch)
tree3338d1830d451467b83af71d44ec91e7aef529a0 /vespa-http-client
parent54c581949ccfaa61942e5c209fe7c02b9d172893 (diff)
Make close finish when network is unavailable.
Diffstat (limited to 'vespa-http-client')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java46
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java2
2 files changed, 23 insertions, 25 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java
index bc41e74c36d..505039cd2d4 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java
@@ -140,39 +140,37 @@ class IOThread implements Runnable, AutoCloseable {
if (! running.await(2 * localQueueTimeOut, TimeUnit.MILLISECONDS)) {
log.info("Waited " + 2 * localQueueTimeOut
+ " ms for queue to be empty, did not happen, interrupting thread.");
- thread.interrupt();
- try {
- running.await();
- log.info("Now thread finished (after interrupt).");
- } catch (InterruptedException e) {
- log.log(Level.INFO, "Interrupted while waiting for threads to finish after they were interrupted.", e);
- }
}
} catch (InterruptedException e) {
- log.log(Level.INFO, "Interrupted while waiting for threads to finish.", e);
+ log.log(Level.INFO, "Interrupted while waiting for threads to finish sending.", e);
}
- try {
- if (resultQueue.getPendingSize() > 0) {
- log.info("We have outstanding operations, maybe we did an interrupt? Draining.");
+ // Make 5 attempts the next 30 secs to get results from previous operations.
+ for (int i = 0 ; i < 5; i++) {
+ int size = resultQueue.getPendingSize();
+ if (size == 0) break;
+ log.info("We have outstanding operations (" + size +") , waiting for responses, iteraton: " + i + ".");
+
+ try {
processResponse(client.drain());
+ } catch (Throwable e) {
+ log.log(Level.SEVERE, "Some failures while trying to get latest responses from vespa.", e);
+ break;
}
- } catch (Exception e) {
- drainDocumentQueueWhenFailingPermanently(e);
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- } else {
- throw new RuntimeException(e);
- }
- } finally {
try {
- client.close();
- } finally {
- // If there is still documents in the queue, fail them.
- drainDocumentQueueWhenFailingPermanently(new Exception(
- "Closed call, did not manage to process everything so failing this document."));
+ Thread.sleep(6000);
+ } catch (InterruptedException e) {
+ break;
}
}
+ try {
+ client.close();
+ } finally {
+ // If there is still documents in the queue, fail them.
+ drainDocumentQueueWhenFailingPermanently(new Exception(
+ "Closed call, did not manage to process everything so failing this document."));
+ }
+
log.fine("Session to " + endpoint + " closed.");
}
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java
index b0c3ba3c1ac..3029025d4cc 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java
@@ -31,7 +31,7 @@ public class FormatInputStream {
* @param stream InputStream of the data if present
* @param inputFile Path to file to use as input
* @param addRootElementToXml To add vespafeed root element around the input data stream
- * @throws IOException
+ * @throws IOException on errors.
*/
public FormatInputStream(InputStream stream, Optional<String> inputFile, boolean addRootElementToXml)
throws IOException {