Skip to content

Commit 1be794f

Browse files
committed
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
1 parent ad82e8d commit 1be794f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/ClassPathChangeUploader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,8 +19,8 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
2121
import java.io.ObjectOutputStream;
22-
import java.net.ConnectException;
2322
import java.net.MalformedURLException;
23+
import java.net.SocketException;
2424
import java.net.URI;
2525
import java.net.URISyntaxException;
2626
import java.net.URL;
@@ -117,9 +117,10 @@ private void performUpload(ClassLoaderFiles classLoaderFiles, byte[] bytes)
117117
logUpload(classLoaderFiles);
118118
return;
119119
}
120-
catch (ConnectException ex) {
121-
logger.warn("Failed to connect when uploading to " + this.uri
120+
catch (SocketException ex) {
121+
logger.warn("A failure occurred when uploading to " + this.uri
122122
+ ". Upload will be retried in 2 seconds");
123+
logger.debug("Upload failure", ex);
123124
Thread.sleep(2000);
124125
}
125126
}

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/ClassPathChangeUploaderTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
2020
import java.io.File;
2121
import java.io.IOException;
2222
import java.io.ObjectInputStream;
23-
import java.net.ConnectException;
23+
import java.net.SocketException;
2424
import java.util.Collection;
2525
import java.util.Iterator;
2626
import java.util.LinkedHashSet;
@@ -111,10 +111,10 @@ public void sendsClassLoaderFiles() throws Exception {
111111
}
112112

113113
@Test
114-
public void retriesOnConnectException() throws Exception {
114+
public void retriesOnSocketException() throws Exception {
115115
File sourceFolder = this.temp.newFolder();
116116
ClassPathChangedEvent event = createClassPathChangedEvent(sourceFolder);
117-
this.requestFactory.willRespond(new ConnectException());
117+
this.requestFactory.willRespond(new SocketException());
118118
this.requestFactory.willRespond(HttpStatus.OK);
119119
this.uploader.onApplicationEvent(event);
120120
assertThat(this.requestFactory.getExecutedRequests()).hasSize(2);

0 commit comments

Comments
 (0)