Skip to content

Commit e187ada

Browse files
author
Karl Rieb
committed
Update longpoll example to workaround server-side connection reset bug.
1 parent 9fa0817 commit e187ada

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- Replace public final references in DbxClientV2 and DbxTeamClientV2 with accessor methods.
2+
- Update longpoll example to workaround connection resets.
23

34
---------------------------------------------
45
2.0-beta-7 (2016-02-24)

examples/longpoll/src/com/dropbox/core/examples/longpoll/Main.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.dropbox.core.DbxException;
66
import com.dropbox.core.DbxRequestConfig;
77
import com.dropbox.core.DbxWebAuth;
8+
import com.dropbox.core.NetworkIOException;
89
import com.dropbox.core.json.JsonReader;
910
import com.dropbox.core.http.StandardHttpRequestor;
1011
import com.dropbox.core.v2.DbxClientV2;
@@ -17,6 +18,7 @@
1718
import com.dropbox.core.v2.files.Metadata;
1819

1920
import java.io.IOException;
21+
import java.net.SocketTimeoutException;
2022
import java.util.Locale;
2123
import java.util.concurrent.TimeUnit;
2224
import java.util.logging.Level;
@@ -33,7 +35,8 @@ public class Main {
3335
* periodic polling the endpoint.
3436
*/
3537
public static void longpoll(DbxAuthInfo auth, String path) throws IOException {
36-
long longpollTimeoutSecs = TimeUnit.MINUTES.toSeconds(2);
38+
// Keep timeout low to avoid issue with reset/dropped connections
39+
long longpollTimeoutSecs = 30;
3740

3841
// need 2 Dropbox clients for making calls:
3942
//
@@ -70,6 +73,7 @@ public static void longpoll(DbxAuthInfo auth, String path) throws IOException {
7073
Long backoff = result.getBackoff();
7174
if (backoff != null) {
7275
try {
76+
System.out.printf("backing off for %d secs...\n", backoff.longValue());
7377
Thread.sleep(TimeUnit.SECONDS.toMillis(backoff));
7478
} catch (InterruptedException ex) {
7579
System.exit(0);
@@ -82,6 +86,12 @@ public static void longpoll(DbxAuthInfo auth, String path) throws IOException {
8286
System.err.println("Error making API call: " + message);
8387
System.exit(1);
8488
return;
89+
} catch (NetworkIOException ex) {
90+
System.err.println("Error making API call: " + ex.getMessage());
91+
if (ex.getCause() instanceof SocketTimeoutException) {
92+
System.err.println("Consider increasing socket read timeout and decreasing longpoll timeout");
93+
}
94+
System.exit(1);
8595
} catch (DbxException ex) {
8696
System.err.println("Error making API call: " + ex.getMessage());
8797
System.exit(1);

0 commit comments

Comments
 (0)