55import com .dropbox .core .DbxException ;
66import com .dropbox .core .DbxRequestConfig ;
77import com .dropbox .core .DbxWebAuth ;
8+ import com .dropbox .core .NetworkIOException ;
89import com .dropbox .core .json .JsonReader ;
910import com .dropbox .core .http .StandardHttpRequestor ;
1011import com .dropbox .core .v2 .DbxClientV2 ;
1718import com .dropbox .core .v2 .files .Metadata ;
1819
1920import java .io .IOException ;
21+ import java .net .SocketTimeoutException ;
2022import java .util .Locale ;
2123import java .util .concurrent .TimeUnit ;
2224import 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