diff options
Diffstat (limited to 'vespa-http-client')
2 files changed, 13 insertions, 6 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 1764016bae6..b931a7f2617 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 @@ -347,11 +347,16 @@ public class IOThread implements Runnable, AutoCloseable { currentConnection.handshake(); successfulHandshakes.getAndIncrement(); } catch (ServerResponseException ser) { + int code = ser.getResponseCode(); + if (code == 401 || code == 403) { + drainDocumentQueueWhenFailingPermanently(new Exception("Denied access by endpoint:" + ser.getResponseString())); + log.log(Level.SEVERE, "Failed authentication or authorization with '" + endpoint + "': " + Exceptions.toMessageString(ser)); + return ConnectionState.CONNECTED; // Should ideally exit immediately, instead of doing this per X documents :/ + } executeProblemsCounter.incrementAndGet(); log.log(Level.INFO, "Failed talking to endpoint. Handshake with server endpoint '" + endpoint + - "' failed. Will re-try handshake.", - ser); + "' failed -- will re-try handshake: " + Exceptions.toMessageString(ser)); drainFirstDocumentsInQueueIfOld(); resultQueue.onEndpointError(new FeedProtocolException(ser.getResponseCode(), ser.getResponseString(), ser, endpoint)); diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/IOThreadTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/IOThreadTest.java index c5913d73d7b..240adc29197 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/IOThreadTest.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/communication/IOThreadTest.java @@ -41,18 +41,20 @@ public class IOThreadTest { } @Test - public void testExceptionOnConnect() { + public void testFatalExceptionOnHandshake() { OperationProcessorTester tester = new OperationProcessorTester(); IOThread ioThread = tester.getSingleIOThread(); DryRunGatewayConnection firstConnection = (DryRunGatewayConnection)ioThread.currentConnection(); firstConnection.throwOnHandshake(new ServerResponseException(403, "Not authorized")); tester.send("doc1"); + tester.send("doc2"); + tester.send("doc3"); tester.tick(3); - assertEquals(1, tester.incomplete()); + assertEquals(0, tester.incomplete()); assertEquals(0, ioThread.resultQueue().getPendingSize()); assertEquals(0, tester.success()); - assertEquals("Awaiting retry", 0, tester.failures()); + assertEquals(3, tester.failures()); } @Test @@ -60,7 +62,7 @@ public class IOThreadTest { OperationProcessorTester tester = new OperationProcessorTester(); IOThread ioThread = tester.getSingleIOThread(); DryRunGatewayConnection firstConnection = (DryRunGatewayConnection)ioThread.currentConnection(); - firstConnection.throwOnHandshake(new ServerResponseException(403, "Not authorized")); + firstConnection.throwOnHandshake(new ServerResponseException(418, "I'm a teapot")); tester.send("doc1"); tester.tick(3); |