From: Bill Erickson Date: Tue, 5 Aug 2014 20:25:18 +0000 (-0400) Subject: Cache login results before sending response to client X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Fmultiplex-squash-tmp;p=working%2FSIPServer.git Cache login results before sending response to client Signed-off-by: Bill Erickson --- diff --git a/SIPServer.pm b/SIPServer.pm index 316c234..0888ed0 100644 --- a/SIPServer.pm +++ b/SIPServer.pm @@ -225,7 +225,6 @@ sub check_pending_connections { my $values = $cache->get_multi(@keys); for my $key (keys %$values) { - my $VAR1; # for Dump() -> eval; eval $values->{$key}; # Data::Dumper->Dump string @@ -319,42 +318,54 @@ sub mux_input { if ($pid == 0) { # in kid - eval { &$transport($self, $str_fh) }; + $cache = undef; # don't use the same cache handle as our parent. + my $cache_data = {id => $conn_id}; - my $success = 1; - if ($@) { - syslog('LOG_ERR', "ILS login error: $@"); - $success = 0; - } else { - # Grab any state data for later - $self->{state} = $self->{ils}->state() if (UNIVERSAL::can($self->{ils},'state')); + # Once the login dance is complete in SipMsg, login_complete() is + # called so that we may cache the results before the login response + # message is delivered to the client. + $self->{login_complete} = sub { + my $status = shift; - # Evergreen, at least, needs a chance to clean up before forking for other requests - $self->{ils}->disconnect() if (UNIVERSAL::can($self->{ils},'disconnect')); + if ($status) { # login OK - # Stash the ILS module somewhere handy for later - $self->{ils} = ref($self->{ils}); - } - - my $info = { - id => $conn_id, - success => $success, - net_server_parts => { - map { ($_ => $$self{$_}) } qw/ils state institution account/ + $self->{state} = $self->{ils}->state() if (UNIVERSAL::can($self->{ils},'state')); + + # Evergreen, at least, needs a chance to clean up before forking for other requests + $self->{ils}->disconnect() if (UNIVERSAL::can($self->{ils},'disconnect')); + + # Stash the ILS module somewhere handy for later + $self->{ils} = ref($self->{ils}); + + $cache_data->{success} = 1; + $cache_data->{net_server_parts} = { + map { ($_ => $$self{$_}) } qw/ils state institution account/ + }; + } else { + $cache_data->{success} = 0; } + + init_cache()->set( + "sip_pending_auth_$$", + Data::Dumper->Dump([$cache_data]), + # Our cache entry is only inspected when the parent process + # wakes up from an inbound request. If this is the last child + # to connect before a long period of inactivity, our cache + # entry may sit unnattended for some time, hence the + # 12 hour cache timeout. XXX: make it configurable? + 43200 # 12 hours + ); + + $self->{login_complete_called} = 1; }; - init_cache()->set( - "sip_pending_auth_$$", - Data::Dumper->Dump([$info]), - # Our cache entry is only inspected when the parent process - # wakes up from an inbound request. If this is the last child - # to connect before a long period of inactivity, our cache - # entry may sit unnattended for some time, hence the - # 12 hour cache timeout. XXX: make it configurable? - 43200 # 12 hours - ); - + eval { &$transport($self, $str_fh) }; + + if ($@) { + syslog('LOG_ERR', "ILS login error: $@"); + $self->{login_complete}->(0) unless $self->{login_complete_called}; + } + exit(0); } else { @@ -376,7 +387,7 @@ sub mux_input { if ($pid == 0) { # in kid # build the connection we deleted after logging in - $self->{ils}->use; + $self->{ils}->use; # module name in the parent $self->{ils} = $self->{ils}->new($self->{institution}, $self->{account}, $self->{state}); # MUX mode only works with protocol version 2, because it assumes diff --git a/Sip/MsgType.pm b/Sip/MsgType.pm index 543838e..779d41d 100644 --- a/Sip/MsgType.pm +++ b/Sip/MsgType.pm @@ -859,6 +859,8 @@ sub handle_login { _load_ils_handler($server, $uid); } + $server->{login_complete}->($status) if $server->{login_complete}; + $self->write_msg(LOGIN_RESP . $status); return $status ? LOGIN : '';