Warn when sending very large messages
authorBill Erickson <berick@esilibrary.com>
Tue, 18 Oct 2011 13:17:10 +0000 (09:17 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 18 Oct 2011 13:51:28 +0000 (09:51 -0400)
Depending on configuration, messages of a certain size sent through a
Jabber server will cause the jabber server to disconnect the client.
This change allows admins to configure a message size warning threshold.
When a message meets or exceeds the size threshold, a warning is issued
to the logs with the message size (in bytes) and the message recipient.
It does not prevent the message from being delivered.  It's purely
informational.

Use 1 800 000 as the default threhold.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

examples/opensrf_core.xml.example
src/perl/lib/OpenSRF/Transport/SlimJabber/Client.pm

index a1f2498..816a20c 100644 (file)
@@ -41,6 +41,9 @@ vim:et:ts=2:sw=2:
         this should match one of the <name> of the private router above -->
     <router_name>router</router_name>
 
+    <!-- Log a warning when an outbound message reaches this size in bytes -->
+    <msg_size_warn>1800000</msg_size_warn>
+
     <!-- log file settings ======================================  -->
     <!-- log to a local file -->
     <logfile>LOCALSTATEDIR/log/osrfsys.log</logfile>
index 2db8be7..a3f9233 100644 (file)
@@ -109,7 +109,15 @@ sub send {
     my $msg = OpenSRF::Transport::SlimJabber::XMPPMessage->new(@_);
     $msg->osrf_xid($logger->get_osrf_xid);
     $msg->from($self->xmpp_id);
-    $self->reader->send($msg->to_xml);
+    my $xml = $msg->to_xml;
+    { 
+        use bytes; 
+        my $len = length($xml);
+        if ($len >= $self->{msg_size_warn}) {
+            $logger->warn("Sending large message of $len bytes to " . $msg->to)
+        }
+    }
+    $self->reader->send($xml);
 }
 
 =head2 initialize
@@ -128,6 +136,8 @@ sub initialize {
 
        my $conf = OpenSRF::Utils::Config->current;
 
+    $self->{msg_size_warn} = $conf->bootstrap->msg_size_warn || 1800000;
+
        my $tail = "_$$";
        $tail = "" if !$conf->bootstrap->router_name and $username eq "router";
     $resource = "$resource$tail";