Return back to the blog

Shutting down can be tough….

Posted by Prashant Deva on December 7, 2010

In my last post I talked about ‘flusher threads’ which constantly ‘flush’ the recorded data from the memory buffer and persist it to disk.

However, due to the latencies in IO between memory and hard disk, it is entirely possible that your program terminates while there is still some data left in the memory buffer which hasn’t been persisted.

To solve this issue, we register a ‘shutdown hook’ with the jvm which essentially keeps your program alive for a little while even after it terminates, so that we can persist all the leftover data. That is why you may see messages like these  on your console when your program shuts down when its running with Chronon.

Console-output

However using the shutdown hook opens a whole can of worms of its own.

Since the jvm does not impose any sort of ordering of how shutdown hooks are run, we essentially ‘stop’ recording at this point. Thus if you have any custom shutdown hooks of your own, those will not be recorded.

There are also issues where the shutdown hook does not run, in which case the recording would be considered corrupt.

Some of the cases when the shutdown hook will run are :

  • Program finishes execution normally.
  • Program calls System.exit().
  • Ctrl+C is used to kill the program.
  • An uncaught exception terminates the program.
  • The unix ‘kill’ command is used to terminate the program.

Cases when the shutdown hook does not run, thus leaving the recording in an invalid state :

  • Program calls Runtime.halt().
  • Unix command ‘kill -9′ is used to terminate the program.
  • The ‘End Process’ option of the Windows Task Manager is used to terminate the program.
  • Internal JVM crashes or crashes inside the native code.
  • Any other program which sends a SIGKILL signal on an Unix machine or the TerminateProcess call on a Windows machine.

That said, most of our used will be using eclipse to launch and terminate their programs, so I really focused on making that use case always produce a valid recording.

Eclipse by itself unfortunately doesn’t seem to be of any help in this case since the default red ‘terminate’ button sends a SIGKILL signal thus terminating the JVM instantly without waiting for any shutdown hooks to run. Thus if you use the ‘red’ button to terminate your programs running with Chronon, the recording will always be invalid.

Console-red

So I went ahead and added a ‘blue’ button next to the ‘red’ terminate button.

Console-blue

Pushing the ‘blue’ button will make sure the shutdown hook runs and you always get a valid recording. The blue button is active only when a program is running with Chronon enabled and it is what you should always use to stop your programs from within Eclipse.

You can still use the ‘red’ button when say you were just experimenting with something and no bugs appeared or for some other reason you just don’t care about the recording, but we recommend making the blue button your default for stopping programs from now on.

Tagged , , 2 Comments |

2 thoughts on “Shutting down can be tough….

  1. From a UI consistency standpoint, I would recommend that you change the blue button to be red and add an annotation image to it. Say a pair of wings (just thinking out loud), to indicate an "angelic" shutdown over a hard and fast kill. Green means go/good, red means stop/kill and blue means ??? You are changing user thought metaphors for you product but you are not really changing the meaning of stopping the jvm, just how it has been "enhanced" to save before stopping, thus you should annotate the image.Now one could argue that the blue rectangle _is_ your annotation, in which case I would say it’s too big and should have some red in it.Final note, I think your product is very cool and I’m glad I voted for it and that it won at the EclipseCon 2011 new product showcase.

  2. Wendell, Having 2 red buttons would confuse the user even more.The color is blue because the record button is also blueish. Its not the exact same color as the record button since it has to be the same brightness as the red button.I dont think we are changing metaphors or behavior in any way. Red still means kill without second thought. We just added blue to means kills gracefully.Our aim was to have the same button as stop, but with a different color. Same as how we do it with the ‘record’ button. Its the same as the ‘run’ button but with a different color. We have observed that just changing colors feels more natural and easy to grasp for users than a whole new button.Thanks for voting for us at EclispeCon :)

Comments are closed.