LPXXX Avoid logging dupe NOT CONNECTED errors user/berick/lpxxx-no-repeat-not-connected
authorBill Erickson <berickxx@gmail.com>
Wed, 17 May 2023 15:48:13 +0000 (11:48 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 17 May 2023 15:48:13 +0000 (11:48 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/perl/lib/OpenSRF/Transport.pm

index 5aeff4d..27aa59d 100644 (file)
@@ -66,6 +66,17 @@ the handler method on the message document.
 
 =cut
 
+# Track remote-id's / addresses for clients which sent us a request, but
+# are no longer connected to the message bus.  In cases where a client
+# goes away during an API call that produces many responses, the "not
+# connected" error logs below will repeat per response, which could be
+# quite a bit of repititive logging.
+#
+# We could track this as session-level information instead, but the
+# assumption is that this list will not grow large unless your system is
+# already unusable.
+my %lost_callers;
+
 sub handler {
        my $start_time = time();
        my( $class, $service, $data ) = @_;
@@ -79,11 +90,16 @@ sub handler {
 
        $logger->set_osrf_xid($data->osrf_xid);
 
+    if (defined($type) and $type eq 'error') {
+        if ($lost_callers{$remote_id}) {
+            # We've already raised an exception and logged a warning about
+            # this caller disappearing.
+            return 0;
+        }
 
-       if (defined($type) and $type eq 'error') {
-               throw OpenSRF::EX::Session ("$remote_id IS NOT CONNECTED TO THE NETWORK!!!");
-
-       }
+        $lost_callers{$remote_id} = 1;
+        throw OpenSRF::EX::Session ("$remote_id IS NOT CONNECTED TO THE NETWORK!!!");
+    }
 
        # See if the app_session already exists.  If so, make 
        # sure the sender hasn't changed if we're a server