From 03335ab401576355dfc5bcee1aa45714fd9fc411 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: Tomas Cohen Arazi --- C4/SIP/SIPServer.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 7e9c620218..e891a054e2 100755 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -238,6 +238,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: @@ -254,8 +255,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 @@ -281,6 +284,7 @@ sub sip_protocol_loop { } # We successfully received and processed what we were expecting $expect = ''; + alarm 0; } } -- 2.39.5