summaryrefslogtreecommitdiffstats
path: root/vespa-http-client
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-10-18 07:46:24 +0200
committerGitHub <noreply@github.com>2018-10-18 07:46:24 +0200
commit7e7ff62f6d9352cc196a62a67ab64e1bb6c94361 (patch)
tree3d39cf9ad43ef965aeb81d00ad7fbd97cb97b93a /vespa-http-client
parent6a64d4aa2d5a266d83117c22c3ab8f9d543af8c7 (diff)
parentff3929298b5d25511cec88ee987e9f81eb8d7f02 (diff)
Merge pull request #7347 from vespa-engine/balder/avoid-deadlocking-yourself
Balder/avoid deadlocking yourself
Diffstat (limited to 'vespa-http-client')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/DocumentQueue.java4
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java2
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/CloseableQTestCase.java14
3 files changed, 15 insertions, 5 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/DocumentQueue.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/DocumentQueue.java
index d963ae79227..2b746cf56d0 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/DocumentQueue.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/DocumentQueue.java
@@ -38,10 +38,10 @@ class DocumentQueue {
}
}
- void put(Document document) throws InterruptedException {
+ void put(Document document, boolean self) throws InterruptedException {
document.resetQueueTime();
synchronized (queue) {
- while (!closed && queue.size() >= maxSize) {
+ while (!closed && (queue.size() >= maxSize) && !self) {
queue.wait();
}
if (closed) {
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 f3cb0b7bcf7..328260e6761 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
@@ -165,7 +165,7 @@ class IOThread implements Runnable, AutoCloseable {
public void post(final Document document) throws InterruptedException {
- documentQueue.put(document);
+ documentQueue.put(document, Thread.currentThread() == thread);
}
@Override
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/CloseableQTestCase.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/CloseableQTestCase.java
index 13129dba326..82538179ef9 100644
--- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/CloseableQTestCase.java
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/CloseableQTestCase.java
@@ -4,13 +4,14 @@ package com.yahoo.vespa.http.client.core.communication;
import com.yahoo.vespa.http.client.core.Document;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class CloseableQTestCase {
@Test
public void requestThatPutIsInterruptedOnClose() throws InterruptedException {
final DocumentQueue q = new DocumentQueue(1);
- q.put(new Document("id", "data", null /* context */));
+ q.put(new Document("id", "data", null /* context */), false);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
@@ -25,7 +26,7 @@ public class CloseableQTestCase {
});
t.start();
try {
- q.put(new Document("id2", "data2", null /* context */));
+ q.put(new Document("id2", "data2", null /* context */), false);
fail("This shouldn't have worked.");
} catch (IllegalStateException ise) {
// ok!
@@ -35,4 +36,13 @@ public class CloseableQTestCase {
} catch (InterruptedException e) {
}
}
+
+ @Test
+ public void requireThatSelfIsUnbounded() throws InterruptedException {
+ DocumentQueue q = new DocumentQueue(1);
+ q.put(new Document("1", "data", null /* context */), true);
+ q.put(new Document("2", "data", null /* context */), true);
+ q.put(new Document("3", "data", null /* context */), true);
+ assertEquals(3, q.size());
+ }
}