Safely timing out DBI queries



Greetings all. I'm working on an app which allows users to construct
queries using a web UI in a moderately free-form fashion. There's
plenty of data and hence plenty of rope. I need to save my users from
themselves by timing-out long-running queries and killing the MySQL
thread.

Our first attempt used alarm() and $SIG{ALRM}. For reasons described
in the DBI docs, this didn't work - the alarm fires, but only after
the database is done with the query. I did try the POSIX sigaction()
recipe from the docs, and it worked. However, I'm very nervous about
the possibility of random instability inherent in unsafe signals. I'm
hoping to find a better way.

At present I'm imagining something like:

- Parent forks a child before starting long-running query.

- Child sleeps for $timeout seconds.

- If parent finishes first, kills child and proceeds.

- If child wakes up, kills parent's MySQL thread ID and exits.
Parent gets "lost connection during query" and assumes that's a
timeout.

I am concerned about a race condition here. What happens when the
parent finishes just before the child wakes up? Seems to me the child
could kill the parent's connection and the parent might not notice.
In my case I think I can get away with this - when the parent finishes
it's about the exit() itself, and doesn't need its DB handle anymore.
I'd like to have a recipe that didn't have this potential problem
though, since I forsee needing this elsewhere in the future.

Ideas? Am I better off giving in to darkside of POSIX?

-sam
.



Relevant Pages

  • Re: Difficulty in implementing
    ... The textual content in the parent table will make the "table wider". ... textual column is involved in other queries, storing it in a child table ... you will get better performance by storing it in a child ...
    (microsoft.public.sqlserver.fulltext)
  • Please help
    ... LotId can have 1-8 components). ... Both parent and child ... When I run queries on ... it best to copy that information from parent to child lot. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Linking 4 child tables to 1 Parent table
    ... There are situations in which keeping 1-1 "child" tables makes more sense. ... separate tables will probably be OK. ... I'm not clear which queries you are referring to, but I do know that you can ... right now they are linked to the key field of the parent, ...
    (microsoft.public.access.tablesdbdesign)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)