[Spread-users] Spread Perl Signal Handling Problem and Thread Safety

Gordan Bobic gordan at bobich.net
Fri Mar 23 11:40:17 EDT 2007


I just thought I'd post here, just in case somebody else runs into this 
problem.

Using the Spread::receive() method without the timeout parameter 
completely breaks signal traps in Perl. If you write your own signal 
traps, they will never trigger, and the signal will instead get silently 
eaten.

For example, if you have something like:

################################################
$SIG{INT} = sub { #some cleanup };

my($mbox, $private_group) = Spread::connect
(
	{
        	spread_name	=> '4444 at localhost',
		private_name	=> 'listener'
	}
);

Spread::join($mbox, 'channel');

while (1)
{
	@Data = Spread::receive($mbox);

	# Do some work with @Data
}
###############################################

If you try to Ctrl+C the program, it will not exit AND the SIGINT handler 
will never trigger.

This also seems to hold for other signals I have tested (e.g. ALRM). This 
is, IMO, a _MAJOR_ bug. It should at the very least be documented.

There is, however, a workaround (or so it would seem). If you specify a 
timeout, the signal passing starts to work again!

Replacing the receive() line above with something like:
@Data = Spread::receive($mbox, 60);

will make signal handling work again.

On a separate subject, is there a thread/fork safe version of the Spread 
libraries for perl? It would be really useful if I could have multiple 
message receiving threads that don't all receive all the messages. I know 
this can be partially worked around by having one receiver and then 
writing to multiple pre-forked processors through a socket (or IPC), but 
this seems unnecessarily tedious and sub-optimal.

Gordan





More information about the Spread-users mailing list