← Back to team overview

maria-discuss team mailing list archive

Re: Why isn't SO_SNDTIMEO used?

 

Hi!

>>>>> "Kristian" == Kristian Nielsen <knielsen@xxxxxxxxxxxxxxx> writes:

>> On Wed, Mar 10, 2010 at 12:29 PM, Michael Widenius <monty@xxxxxxxxxxxx> wrote:
>>> We also use the thr_alarm() functionality when one uses 'kill
>>> connection-id' in MySQL.  I don't know of any easy way to gracefully
>>> wake up a thread that is sleeping on SO_SNDTIMEO. Do you?

Kristian> Well, I checked the code, and it seems to wake up the thread using
Kristian> pthread_kill(thread, signal) for the 'kill connection-id' command. This should
Kristian> work fine also when using SO_SNDTIMEO for timeouts on the socket.

Kristian> Just send the signal to the thread blocking on the socket with SO_SNDTIMEO,
Kristian> and the blocking socket call will return with EAGAIN or similar.

It's not that easy.

The problem is the following:

The alarm code now makes sure that we don't send the signal if we are
not waiting for it;  I may not be safe for the thread to receive the
kill signal at any point in time (for example in thread engine code,
which we don't want to interrupt).

The alarm code makes sure that the signal is never missed.  For
example, if we would send the signal just before we enter read with
SNO_SNDTIMEO, the thread would miss the signal and the 'kill command'
would not have any effect.

To solve this, we would need to add the following mechanism:

- Add a flag to THD that signals if we are in a read() call on
  a connection.  This flag should be modified under a mutex to ensure
  that the 'kill thread-id' code knows if it should send a signal or
  not.

- The kill code should send multiple kill commands to the thread,
  until the 'read()' flag changes state to 'not in read'.

Possible to do, but still a little bit of work and test.

Regards,
Monty



Follow ups

References