Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The polling function of Host.lazyStart not functional #9

Open
adb014 opened this issue Nov 23, 2024 · 0 comments
Open

The polling function of Host.lazyStart not functional #9

adb014 opened this issue Nov 23, 2024 · 0 comments

Comments

@adb014
Copy link

adb014 commented Nov 23, 2024

Due to the fact the local variales must be final in java lambda function the Runnable poll in lazyStart seems to have moved the variable pollcounter into poll. The existing code is

        Runnable poll =  new Runnable() {
            public void run() {

                int pollcounter = 0;
                pollcounter++;
                // host still is unreachable start host
                if ( tunnel.isOpen()){
                    if (pollcounter * period < 10000){ // 60 seconds # TODO make configurable
                        connecting = executor.schedule(this,period,TimeUnit.MILLISECONDS);
                    } else{

                        logger.debug("start command after:",(period * pollcounter ) / 1000);
                        starting = executor.schedule(startTask,0,TimeUnit.MILLISECONDS);
                    }
                } else {
                    // if stop command is already running, it will start after stopcommand has finished # TODO not true
                    // because executor is single trheaded
                    starting = executor.schedule(startTask,0,TimeUnit.MILLISECONDS);
                }
            }
        };

As you can see the variable pollcounter is reset to zero at each call to poll this effectively means that if tunnel.isOpen() is always true this poller never exits. I have this case will using guacamoleTrigger with the OAuth authenticator, where it seems that the OAuth authenticator opens the tunnel to guacd, my start script never runs.

Can I propose that rather than using a counter, we set an end data in lazyStart so that the local variable in lazyStartis final. I propose the patch

--- a/src/main/java/org/apache/guacamole/guacamoletrigger/auth/Host.java
+++ b/src/main/java/org/apache/guacamole/guacamoletrigger/auth/Host.java
@@ -235,18 +235,16 @@ public class Host  {
         // if Tunnel is already closed, try to start host direct
         Runnable startTask = new Runnable() { public void run() { start(user, env); }};
         int period = 200;
+        long endpoll = System.currentTimeMillis() + 10000; // 10 seconds # TODO make configurable
         Runnable poll =  new Runnable() {
             public void run() {
-
-                int pollcounter = 0;
-                pollcounter++;
                 // host still is unreachable start host
                 if ( tunnel.isOpen()){
-                    if (pollcounter * period < 10000){ // 60 seconds # TODO make configurable
+                    if (System.currentTimeMillis() < endpoll){
                         connecting = executor.schedule(this,period,TimeUnit.MILLISECONDS);
                     } else{
 
-                        logger.debug("start command after:",(period * pollcounter ) / 1000);
+                        logger.debug("start command at: {}",System.currentTimeMillis());
                         starting = executor.schedule(startTask,0,TimeUnit.MILLISECONDS);
                     }
                 } else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant