• Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing SSH connection kill deamon  RSS feed

 
Joao Del Valle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use a GUI frame in the startup of my application and then it is supposed to be left to run as a daemon, but when I close the SSH session, the app crashes with the error:

X connection to localhost:10.0 host broken (explicit kill or server shutdown)

I isolated the problem with a small program:



Ssh to a remote machine and launch this program with

nohup java T &

After providing the password, exit your SSH session (it will probably exit only after a Ctrl+C since it waits for the X connection to finish). Now when you SSH again to that machine to see if your daemon is running, you won't see it. At the end of the nohup.out, you'll see the ugly "explicit kill" message.

After this example, we can say that there is an open X connection being tunnelled throught the SSH session. So two questions:

1) Why does my Java process crash when this connection is broken?
2) How can I prevent this behavior? Maybe a way to close the x connection in my program, or make it not abort after a connection closure.

Thanks!
Joao.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joao Del Valle:

1) Why does my Java process crash when this connection is broken?

Your program is blocked on the call to showConfirmDialog. When you kill the X client which is tunneling through your SSH connection, showConfirmDialog throws an exception so your code never reaches your while loop.
If you commented out the call to readPassphrase, that while loop would go on forever, until explicitly killed.


2) How can I prevent this behavior? Maybe a way to close the x connection in my program, or make it not abort after a connection closure.

My X skillz are weak so maybe there is some way one can configure your program to live after the connection is severed.
It really depends on what you are trying to do. If I were going to write a client-server program, I would start by making the client and server seperate classes/programs.
 
Joao Del Valle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:

My X skillz are weak so maybe there is some way one can configure your program to live after the connection is severed.
It really depends on what you are trying to do. If I were going to write a client-server program, I would start by making the client and server seperate classes/programs.


The thing is that this isalready the server-side program. It is an EJB module, with a crypto hardware waiting for a password to be started. The GUI has to be on the server in this case. I cannot use the console because the app server (sjes) starts it in background.
 
Joao Del Valle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:

Your program is blocked on the call to showConfirmDialog. When you kill the X client which is tunneling through your SSH connection, showConfirmDialog throws an exception so your code never reaches your while loop.
If you commented out the call to readPassphrase, that while loop would go on forever, until explicitly killed.


I'm sorry, I think I didn't explain it clearly. The problem is after you close the dialog. After that, the program runs smoothly in background, as we started it with nohup &. But when I close the SSH session it crashes, probably because it kept an open connection to the X server.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joao Del Valle:
But when I close the SSH session it crashes, probably because it kept an open connection to the X server.


Yea, nohup will let your program ignore SIGHUP (when you logoff) and & just runs the process in the background. Neither of those commands let your program ignore the X client going away.
Why are you using a GUI to provide a username/password? We use Weblogic and it provides a repository for encrypting passwords. That way one does not need to specify them in scripts.
Can your crypto hardware be configured in some other way? What does the vendor recommend?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!