From 7d13c576791bbf7b4d4c3ad4036d59f01c923164 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 10 Dec 2014 12:27:59 -0500 Subject: [PATCH] Bug 13432 - SIP Server does not respect timeout setting 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 Signed-off-by: Jonathan Druart Signed-off-by: Mason James --- C4/SIP/SIPServer.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 44c58b42f0..2c89a721f6 100644 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -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; } } -- 2.39.5