Bug 13432 - SIP Server does not respect timeout setting
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 10 Dec 2014 17:27:59 +0000 (12:27 -0500)
committerMason James <mtj@kohaaloha.com>
Thu, 26 Feb 2015 02:45:37 +0000 (15:45 +1300)
Koha's SIP server accepts timeout parameters, but those parameters
are only used for the login portion of a telnet transport session.
Other than that, they are ignored, and as long as whatever opened
the connection keeps it open, it will stay open indefinitely.

Test Plan:
1) Set the timeout setting on your SIP server to 10 seconds
2) Modify misc/sip_cli_emulator.pl, add "sleep 100;" directly after line 91
3) Start your SIP server
4) Run the modified sip script with valid parameters
5) Watch the SIP server stderr
6) Note that even though the script waits far too long before continuing,
   the SIP server never kills the connection, and the requests the cli
   script makes come back with valid data.
7) Apply this patch
8) Restart your SIP server
9) Repeat step 4
10) Note that this time you see "SIP Timed Out!" in the SIP server
    stderr and when the script finally makes it's request, it doesn't
    come back with valid data.

Signed-off-by: Colin Campbell <colin.campbell@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Mason James <mtj@kohaaloha.com>

C4/SIP/SIPServer.pm

index 44c58b4..2c89a72 100644 (file)
@@ -240,6 +240,7 @@ sub sip_protocol_loop {
        my $self = shift;
        my $service = $self->{service};
        my $config  = $self->{config};
+    my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30;
        my $input;
 
     # The spec says the first message will be:
@@ -256,8 +257,10 @@ sub sip_protocol_loop {
        # 
        # In short, we'll take any valid message here.
        #my $expect = SC_STATUS;
+    local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; };
     my $expect = '';
     while (1) {
+        alarm $timeout;
         $input = Sip::read_SIP_packet(*STDIN);
         unless ($input) {
             return;            # EOF
@@ -283,6 +286,7 @@ sub sip_protocol_loop {
                }
                # We successfully received and processed what we were expecting
                $expect = '';
+    alarm 0;
        }
 }