RootX11IOErrorHandler not working

Hello,

I have a problem with handling the loss of X11 server connection when executed in a ssh session with X11 forwarding. The corresponding part of the code is:

TApplication app;
TCanvas *canvas = new TCanvas();
//some graphics output
canvas->Connect("Closed()", "TApplication", &app, "Terminate()");
app.Run(true);

This correctly displays the canvas and allows the user to interact with it and also continues to run after the canvas is closed. However, when the connection to the X11 server is lost, the program does not proceed but starts to consume 100 % CPU. The last thing which gets displayed (obtained via running in background, redirecting to file and forcing the ssh session to quit) is:

Error in <RootX11IOErrorHandler>: fatal X11 error (connection to server lost?!)

**** Save data and exit application ****

Similar behavior occurs when the program is run in the foreground, with the opened canvas it is paused (CTRL+Z), set to background (bg) and again by loosing the connection.
Also the CPU consuming can be reproduced by simply running this in a ssh session without X11 forwarding, but in that case no error message is shown at all.

The program is compiled with gcc 4.6.3 on Ubuntu 12.04 with the proper ROOT flags.

The CPU consumption is very irritating as one has to check that manually and kill the program if it happens. Please help.