Commit 1be794fe authored by Andy Wilkinson's avatar Andy Wilkinson

Retry upload for any SocketException not just a ConnectException

Previously, DevTools would retry the upload of the changes to an
application in the event of a ConnectException. If a different
network-level failure occurred, it would not be retried and would
cause the file watching thread to die.

This commit attempts to make things more robust by retrying all
SocketExceptions and not just ConnectExceptions. A warning is
logged when a failure occurs. A separate debug message that
includes the exception is also logged.

Closes gh-10317
parent ad82e8d1
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,8 +19,8 @@ package org.springframework.boot.devtools.remote.client; ...@@ -19,8 +19,8 @@ package org.springframework.boot.devtools.remote.client;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
...@@ -117,9 +117,10 @@ public class ClassPathChangeUploader ...@@ -117,9 +117,10 @@ public class ClassPathChangeUploader
logUpload(classLoaderFiles); logUpload(classLoaderFiles);
return; return;
} }
catch (ConnectException ex) { catch (SocketException ex) {
logger.warn("Failed to connect when uploading to " + this.uri logger.warn("A failure occurred when uploading to " + this.uri
+ ". Upload will be retried in 2 seconds"); + ". Upload will be retried in 2 seconds");
logger.debug("Upload failure", ex);
Thread.sleep(2000); Thread.sleep(2000);
} }
} }
......
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream; ...@@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.net.ConnectException; import java.net.SocketException;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
...@@ -111,10 +111,10 @@ public class ClassPathChangeUploaderTests { ...@@ -111,10 +111,10 @@ public class ClassPathChangeUploaderTests {
} }
@Test @Test
public void retriesOnConnectException() throws Exception { public void retriesOnSocketException() throws Exception {
File sourceFolder = this.temp.newFolder(); File sourceFolder = this.temp.newFolder();
ClassPathChangedEvent event = createClassPathChangedEvent(sourceFolder); ClassPathChangedEvent event = createClassPathChangedEvent(sourceFolder);
this.requestFactory.willRespond(new ConnectException()); this.requestFactory.willRespond(new SocketException());
this.requestFactory.willRespond(HttpStatus.OK); this.requestFactory.willRespond(HttpStatus.OK);
this.uploader.onApplicationEvent(event); this.uploader.onApplicationEvent(event);
assertThat(this.requestFactory.getExecutedRequests()).hasSize(2); assertThat(this.requestFactory.getExecutedRequests()).hasSize(2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment