Board index » kylix » SIGINT/SIGQUIT blocked after handled exception

SIGINT/SIGQUIT blocked after handled exception


2005-06-09 12:25:19 PM
kylix1
Hi,
I recently stumbled on a problem with exceptions in Kylix3, regarding the
handling of SIGQUIT and SIGINT. A quick peek in the rtl showed that a
thread variable is used to check if the current thread is not handling an
exception on the moment these signals arrive. Two functions control this
variable: BlockOSExceptions and UnblockOSExceptions.
The problem is the following:
When an exception is generated, BlockOSExceptions is called. If
the exception handler is general (no 'on E:Exception do' statement), then
the _HandleAnyException correctly calls UnblockOSExceptions. So far,
nothing new. However, when using a specific exception handler, the
UnblockOSExceptions is never called again. Not even when the exception is
destroyed! This leaves the application in a state where it can no
longer respond to CTRL-C of kill -3 signals.
example code:
-----------------------------------------------------------------------------
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
type MyException = class(Exception);
begin
{ TODO -oUser -cConsole Main : Insert code here }
try
raise MyException.Create('My exception raised');
except
on E: Exception do
begin
writeln('catched exception: ' + E.Message);
//UnblockOSExceptions;
end;
end;
while true do sleep(100);
end.
-----------------------------------------------------------------------------
then try to hit CTRL-C or kill -3 the app...
If you add yourself an UnblockOSExceptions call, then all is fine. This is
NOT a solution for my applications (~150 000 lines of code). My temporary
hack is that I call UnblockOSExceptions on a regular basis (on timer
events); but then again: not a very satisfying solution. Maybe ultimately
one could call it in _DoneExcept, but I have not enough understanding on
this part of the rtl to know this will cover all cases and will not have
any undesired side-effects.
Is there anyone on this group with enough knowledge about exception
handling who knows how to fix this?
kind regards,
Jan
 
 

Re:SIGINT/SIGQUIT blocked after handled exception

Hi,
I recently stumbled on a problem with exceptions in Kylix3, regarding the
handling of SIGQUIT and SIGINT. A quick peek in the rtl showed that a
thread variable is used to check if the current thread is not handling an
exception on the moment these signals arrive. Two functions control this
variable: BlockOSExceptions and UnblockOSExceptions.
The problem is the following:
When an exception is generated, BlockOSExceptions is called. If
the exception handler is general (no 'on E:Exception do' statement), then
the _HandleAnyException correctly calls UnblockOSExceptions. So far,
nothing new. However, when using a specific exception handler, the
UnblockOSExceptions is never called again. Not even when the exception is
destroyed! This leaves the application in a state where it can no
longer respond to CTRL-C of kill -3 signals.
example code:
-----------------------------------------------------------------------------
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
type MyException = class(Exception);
begin
{ TODO -oUser -cConsole Main : Insert code here }
try
raise MyException.Create('My exception raised');
except
on E: Exception do
begin
writeln('catched exception: ' + E.Message);
//UnblockOSExceptions;
end;
end;
while true do sleep(100);
end.
-----------------------------------------------------------------------------
then try to hit CTRL-C or kill -3 the app...
If you add yourself an UnblockOSExceptions call, then all is fine. This is
NOT a solution for my applications (~150 000 lines of code). My temporary
hack is that I call UnblockOSExceptions on a regular basis (on timer
events); but then again: not a very satisfying solution. Maybe ultimately
one could call it in _DoneExcept, but I have not enough understanding on
this part of the rtl to know this will cover all cases and will not have
any undesired side-effects.
Is there anyone on this group with enough knowledge about exception
handling who knows how to fix this?
kind regards,
Jan
 

Re:SIGINT/SIGQUIT blocked after handled exception

Hello,
I already posted this question in june, but got no answer. So let's try
again...
I recently stumbled on a problem with exceptions in Kylix3, regarding the
handling of SIGQUIT and SIGINT. A quick peek in the rtl showed that a
thread variable is used to check if the current thread is not handling an
exception on the moment these signals arrive. Two functions control this
variable: BlockOSExceptions and UnblockOSExceptions.
The problem is the following:
When an exception is generated, BlockOSExceptions is called. If
the exception handler is general (no 'on E:Exception do' statement), then
the _HandleAnyException correctly calls UnblockOSExceptions. So far,
nothing new. However, when using a specific exception handler, the
UnblockOSExceptions is never called again. Not even when the exception is
destroyed! This leaves the application in a state where it can no
longer respond to CTRL-C of kill -3 signals.
example code:
-----------------------------------------------------------------------------
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
type MyException = class(Exception);
begin
{ TODO -oUser -cConsole Main : Insert code here }
try
raise MyException.Create('My exception raised');
except
on E: Exception do
begin
writeln('catched exception: ' + E.Message);
//UnblockOSExceptions;
end;
end;
while true do sleep(100);
end.
-----------------------------------------------------------------------------
then try to hit CTRL-C or kill -3 the app...
If you add yourself an UnblockOSExceptions call, then all is fine. This is
NOT a solution for my applications (~150 000 lines of code). My temporary
hack is that I call UnblockOSExceptions on a regular basis (on timer
events); but then again: not a very satisfying solution. Maybe ultimately
one could call it in _DoneExcept, but I have not enough understanding on
this part of the rtl to know this will cover all cases and will not have
any undesired side-effects.
Is there anyone on this group with enough knowledge about exception
handling who knows how to fix this?
kind regards,
Jan
 

{smallsort}

Re:SIGINT/SIGQUIT blocked after handled exception

On Wed, 20 Jul 2005 21:12:22 +0200, jan < XXXX@XXXXX.COM >wrote:
Quote
Hello,

I already posted this question in june, but got no answer. So let's try
again...

I recently stumbled on a problem with exceptions in Kylix3, regarding the
handling of SIGQUIT and SIGINT. A quick peek in the rtl showed that a
thread variable is used to check if the current thread is not handling an
exception on the moment these signals arrive. Two functions control this
variable: BlockOSExceptions and UnblockOSExceptions.

The problem is the following:
When an exception is generated, BlockOSExceptions is called. If
the exception handler is general (no 'on E:Exception do' statement), then
the _HandleAnyException correctly calls UnblockOSExceptions. So far,
nothing new. However, when using a specific exception handler, the
UnblockOSExceptions is never called again. Not even when the exception is
destroyed! This leaves the application in a state where it can no
longer respond to CTRL-C of kill -3 signals.

Do you know whether this has any other side effects? I have an application
that sometimes does not stop IdHTTP (indy components) threads, thus
leaving 20+ threads active.
Thanks in advance.
Regards,
Diederik