@@ -45,33 +45,38 @@ public void start() {
4545 public void run () {
4646 long processStart = System .nanoTime ();
4747 invokeProcess ().whenComplete ((v , throwable ) -> {
48- if (throwable != null ) {
49- OfcLogger .error ("An error occurred while running proximity worker" , throwable );
50- }
51-
52- if (this .executor .isShutdown ()) {
53- return ;
54- }
55-
56- long processTime = System .nanoTime () - processStart ;
57- this .statistics .proximityProcess .add (processTime );
58-
59- // check if we have enough time to sleep
60- long waitTime = Math .max (0 , this .checkInterval - processTime );
61- long waitMillis = TimeUnit .NANOSECONDS .toMillis (waitTime );
62-
63- if (waitMillis > 0 ) {
64- // measure wait time
65- this .statistics .proximityWait .add (TimeUnit .MILLISECONDS .toNanos (waitMillis ));
66- this .executor .schedule (this , waitMillis , TimeUnit .MILLISECONDS );
67- } else {
68- // Schedule instead of executing directly to break reentrant execution chains of
69- // OrebfuscatorExecutor and avoid potential StackOverflowError.
70- this .executor .schedule (this , 0L , TimeUnit .NANOSECONDS );
71- }
72- }).whenComplete ((v , throwable ) -> {
73- if (throwable != null ) {
74- OfcLogger .error ("An error occurred while running proximity worker, can't recover!" , throwable );
48+ try {
49+ if (throwable != null ) {
50+ OfcLogger .error ("An error occurred while running proximity worker" , throwable );
51+ }
52+
53+ if (this .executor .isShutdown ()) {
54+ return ;
55+ }
56+
57+ long processTime = System .nanoTime () - processStart ;
58+ this .statistics .proximityProcess .add (processTime );
59+
60+ // check if we have enough time to sleep
61+ long waitTime = Math .max (0 , this .checkInterval - processTime );
62+ long waitMillis = TimeUnit .NANOSECONDS .toMillis (waitTime );
63+
64+ if (waitMillis > 0 ) {
65+ // measure wait time
66+ this .statistics .proximityWait .add (TimeUnit .MILLISECONDS .toNanos (waitMillis ));
67+ this .executor .schedule (this , waitMillis , TimeUnit .MILLISECONDS );
68+ } else {
69+ // Schedule instead of executing directly to break reentrant execution chains of
70+ // OrebfuscatorExecutor and avoid potential StackOverflowError.
71+ this .statistics .proximityWait .add (0 );
72+ this .executor .schedule (this , 0L , TimeUnit .NANOSECONDS );
73+ }
74+ } catch (Exception e ) {
75+ OfcLogger .error ("An error occurred while scheduling proximity worker" , e );
76+
77+ // backoff for 1sec on reschedule failure
78+ this .statistics .proximityWait .add (TimeUnit .SECONDS .toNanos (1 ));
79+ this .executor .schedule (this , 1L , TimeUnit .SECONDS );
7580 }
7681 });
7782 }
0 commit comments