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

Groovy script hang on exit if exception thrown within remoteSession #49

Closed
kshtsk opened this issue Jul 5, 2014 · 1 comment
Closed

Comments

@kshtsk
Copy link

kshtsk commented Jul 5, 2014

If you use outer try block for remoteSession and generate exception from within remoteSession it cause the script hang on exit.
Here is code example:

@Grab(group='com.aestasit.infrastructure.sshoogr', module='sshoogr', version='0.9.16')

import static com.aestasit.ssh.DefaultSsh.*
import java.util.concurrent.TimeoutException

setDefaultKeyFile(new File(System.getenv("HOME")+"/.ssh/id_rsa"))
def user = System.getenv("USER")

try {
    remoteSession ("${user}@localhost:22"){
        exec "echo Hello world!"
        throw new TimeoutException("Bang!")
    }
} catch (e) {
    println "Warning: ${e.message}"
}
println "Good bye"

The output looks like follows:

>>> Connecting to localhost
> echo Hello world!
Hello world!
Warning: Bang!
Good bye
@aadamovich
Copy link
Member

Thanks for reporting! I'll take a look at this soon. Most likely the thread that is responsible for reading remote commands output is not stopped because of the exception, that's why the JVM does not exit. You can, of course, force the exit by running System.exit() in the end of your script as a temporary workaround.

aadamovich added a commit that referenced this issue Nov 25, 2014
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

2 participants