Re: [PATCH] avoid bearerbox oom-kill (resend)

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Centrium GmbH
Message-ID <[email protected]>
Hi,

Am Freitag, 15. November 2002 19:00 schrieb Nisan Bloch:
> Hi
>
> please re submit this patch as a unified diff, and ignoring changes to
> white space. This is horrid to read as there are many lines in the diff
> that are not necessary.

sorry for this ;)
here is it ...

>
> nisan
>
>   At 06:49 PM 11/15/02 +0100, Alexander  Malysh wrote:
> >Content-Type: text/plain;
> >   charset="iso-8859-15"
> >X-MIME-Autoconverted: from 8bit to quoted-printable by mail-in-01.piro.net
> >id SAA23798
> >
> >Hi,
> >
> >this is the same oom-kill patch with memleak bugfix.
> >--
> >Mit besten Grüßen aus Köln
> >
> >Dipl.-Ing.
> >Alexander Malysh
> >___________________________________________
> >
> >Centrium GmbH
> >Ehrenstraße 2
> >50672 Köln
> >
> >Fon: +49 (0221) 277 49 150
> >Fax: +49 (0221) 277 49 109
> >
> >email: [email protected]
> >web: www.centrium.de

-- 
Mit besten Grüßen aus Köln

Dipl.-Ing.
Alexander Malysh
___________________________________________

Centrium GmbH
Ehrenstraße 2
50672 Köln

Fon: +49 (0221) 277 49 150
Fax: +49 (0221) 277 49 109

email: [email protected]
web: www.centrium.de
avoid_oom.patch (text/x-diff, 8 KB)
Index: gw/bb_boxc.c
===================================================================
RCS file: /home/cvs/gateway/gw/bb_boxc.c,v
retrieving revision 1.59
diff -a -u -b -r1.59 bb_boxc.c
--- gw/bb_boxc.c	14 Nov 2002 02:29:25 -0000	1.59
+++ gw/bb_boxc.c	15 Nov 2002 18:37:00 -0000
@@ -124,7 +124,8 @@
 static void boxc_receiver(void *arg)
 {
     Boxc *conn = arg;
-    Msg *msg;
+    Msg *msg, *mack;
+    int rc;
 
     /* remove messages from socket until it is closed */
     while (bb_status != BB_DEAD && conn->alive) {
@@ -141,24 +142,38 @@
         if (msg_type(msg) == sms && conn->is_wap == 0) {
             debug("bb.boxc", 0, "boxc_receiver: sms received");
 
-            /* 
-             * XXX save modifies ID, so if the smsbox uses it, save
+		  /* save modifies ID, so if the smsbox uses it, save
              * it FIRST for the reply message!!! 
+		   * generate ack-message and send it - in fact, this
+		   *  should include information did it succeed, wa sit queued
+		   *  or rejected...
              */
+	          mack = msg_create(ack);
+	          mack->ack.id = msg->sms.id;
+	          mack->ack.time = msg->sms.time;
             store_save(msg);
-            if (smsc2_rout(msg)== -1) {
-                warning(0, "Message rejected by bearerbox, no router!");
+		  rc = smsc2_rout(msg);
+                  switch (rc) {
+		      case -1:
+		          warning(0, "Message rejected by bearerbox, no router !");
                 /* send NACK */
                 bb_smscconn_send_failed(NULL, msg, SMSCCONN_FAILED_DISCARDED);
+		          mack->ack.nack = ack_failed;
+		 	  break;
+		      case -2:
+		          warning(0, "Message rejected by bearerbox, queue full !");
+		          /* send NACK */
+	                  bb_smscconn_send_failed(NULL, msg, SMSCCONN_FAILED_DISCARDED);
+		          mack->ack.nack = ack_failed_tmp;
+		 	  break;
+		      case 0:
+		          mack->ack.nack = ack_buffered;
+			  break;
+		      case 1:
+		          mack->ack.nack = ack_success;
+			  break;
             }
-            if (msg->sms.sms_type == mt_push) {
-                /* 
-                 * XXX generate ack-message and send it - in fact, this
-                 * should include information did it succeed, wa sit queued
-                 * or rejected... 
-                 */
-            }
-
+	          list_produce(conn->incoming, mack);
         } else if (msg_type(msg) == wdp_datagram  && conn->is_wap) {
             debug("bb.boxc", 0, "boxc_receiver: got wdp from wapbox");
             
@@ -168,7 +183,7 @@
             debug("bb.boxc", 0, "boxc_receiver: got sms from wapbox");
 
             store_save(msg);
-            if (smsc2_rout(msg)== -1) {
+            if (smsc2_rout(msg) < 0) {
                 warning(0, "Message rejected by bearerbox, no router!");
                 msg_destroy(msg);
             }
@@ -189,7 +204,7 @@
             else if (msg_type(msg) == admin && msg->admin.command == cmd_identify) {
                 List *newlist;
 
-                /* and add the boxc_ud into conn for boxc_status() output */
+                /* and add the boxc_id into conn for boxc_status() output */
                 if (conn->boxc_id == NULL)
                     conn->boxc_id = octstr_duplicate(msg->admin.boxc_id);
                 /* 
Index: gw/bb_smscconn.c
===================================================================
RCS file: /home/cvs/gateway/gw/bb_smscconn.c,v
retrieving revision 1.54
diff -a -u -b -r1.54 bb_smscconn.c
--- gw/bb_smscconn.c	14 Nov 2002 02:29:25 -0000	1.54
+++ gw/bb_smscconn.c	15 Nov 2002 18:37:01 -0000
@@ -175,7 +175,7 @@
     } 
 }    
 
-int bb_smscconn_receive(SMSCConn *conn, Msg *sms)
+long bb_smscconn_receive(SMSCConn *conn, Msg *sms)
 {
     char *uf;
 
@@ -193,13 +193,9 @@
         warning(0, "incoming messages queue too long, dropping a message");
         log_sms(conn, sms, "DROPPED Received SMS");
         gwthread_sleep(0.1); /* letting the queue go down */
-     	return -1;
+     	return SMSCCONN_FAILED_QFULL;
     }
 
-    /* else if (list_len(incoming_sms) > 100)
-     *	gwthread_sleep(0.5);
-     */
-    
     if (unified_prefix == NULL)
     	uf = NULL;
     else
@@ -213,7 +209,7 @@
 	     octstr_get_cstr(sms->sms.sender));
 	log_sms(conn, sms, "REJECTED - not white-listed SMS");
 	msg_destroy(sms);
-        return -1;
+        return SMSCCONN_FAILED_REJECTED;
     }
     if (black_list &&
 	numhash_find_number(black_list, sms->sms.sender) == 1) {
@@ -221,7 +217,7 @@
 	     octstr_get_cstr(sms->sms.sender));
 	log_sms(conn, sms, "REJECTED - black-listed SMS");
 	msg_destroy(sms);
-	return -1;
+	return SMSCCONN_FAILED_REJECTED;
     }
 
     if (sms->sms.sms_type != report)
@@ -229,7 +225,7 @@
     
     /* write to store (if enabled) */
     if (store_save(sms) == -1)
-	return -1;
+	return SMSCCONN_FAILED_TEMPORARILY;
     
     if (sms->sms.sms_type != report)
 	log_sms(conn, sms, "Receive SMS");
@@ -247,7 +243,7 @@
     counter_increase(incoming_sms_counter);
     counter_increase(conn->received);
 
-    return 0;
+    return SMSCCONN_SUCCESS;
 }
 
 
@@ -299,6 +295,11 @@
 	    bb_smscconn_send_failed(NULL, msg, SMSCCONN_FAILED_DISCARDED);
         } else if (ret == 1) {
 	    newmsg = startmsg = NULL;
+	} else if (ret == -2) {
+	    /* bad found and outgoing queue is full, but not for us 
+	    * put message back in outgoing queue
+	    */
+	    list_produce(outgoing_sms, msg);
 	}
 	    
 	    
@@ -664,6 +665,8 @@
  * If finds a good one, puts into it and returns 1
  * If finds only bad ones, but acceptable, queues and
  *  returns 0  (like all acceptable currently disconnected)
+ * If found bad , but maximum_queue_length reached return -2
+ * and message is not destroyed.
  * If cannot find nothing at all, returns -1 and
  * message is NOT destroyed (otherwise it is)
  */
@@ -715,6 +718,7 @@
 	    continue;
 
 	smscconn_info(conn, &info);
+
 	/* If connection is not currently answering... */
 	if (info.status != SMSCCONN_ACTIVE) {
 	    bad_found = 1;
@@ -739,8 +743,12 @@
     else if (best_ok)
 	ret = smscconn_send(best_ok, msg);
     else if (bad_found) {
-	if (bb_status != BB_SHUTDOWN)
+	if (bb_status != BB_SHUTDOWN) {
+	    if (maximum_queue_length != -1 && maximum_queue_length <= list_len(outgoing_sms)) {
+	        return -2;
+	    }
 	    list_produce(outgoing_sms, msg);
+	}
 	return 0;
     }
     else {
Index: gw/bb_smscconn_cb.h
===================================================================
RCS file: /home/cvs/gateway/gw/bb_smscconn_cb.h,v
retrieving revision 1.9
diff -a -u -b -r1.9 bb_smscconn_cb.h
--- gw/bb_smscconn_cb.h	31 Aug 2001 19:54:47 -0000	1.9
+++ gw/bb_smscconn_cb.h	15 Nov 2002 18:37:01 -0000
@@ -41,19 +41,22 @@
 void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason);
 
 enum {
+    SMSCCONN_SUCCESS = 0,
     SMSCCONN_FAILED_SHUTDOWN,
     SMSCCONN_FAILED_REJECTED,
     SMSCCONN_FAILED_MALFORMED,
     SMSCCONN_FAILED_TEMPORARILY,
-    SMSCCONN_FAILED_DISCARDED
+    SMSCCONN_FAILED_DISCARDED,
+    SMSCCONN_FAILED_QFULL
 };
 
 
 /* called when a new message 'sms' received. Callback handles
- * 'sms' and MAY NOT be used by caller again. Return 0 if all went
- * fine, and -1 if bearerbox does NOT accept the 'sms' (black/white
- * -listed) */
-int bb_smscconn_receive(SMSCConn *conn, Msg *sms);
+ * 'sms' and MAY NOT be used by caller again. Return SMSCCONN_SUCCESS if all went
+ * fine, SMSCCONN_FAILED_QFULL if incoming queue full, SMSCCONN_FAILED_TEMPORARILY
+ * if store enabled and failed, and SMSCCONN_FAILED_REJECTED if bearerbox does
+ * NOT accept the 'sms' (black/whitelisted) */
+long bb_smscconn_receive(SMSCConn *conn, Msg *sms);
 
 
 #endif
Index: gw/msg.h
===================================================================
RCS file: /home/cvs/gateway/gw/msg.h,v
retrieving revision 1.13
diff -a -u -b -r1.13 msg.h
--- gw/msg.h	14 Nov 2002 02:29:25 -0000	1.13
+++ gw/msg.h	15 Nov 2002 18:37:01 -0000
@@ -45,6 +45,14 @@
     cmd_suspend = 1,
     cmd_resume = 2,
     cmd_identify = 3
+};
+
+/* ack message status */
+enum {
+    ack_success = 0,
+    ack_failed = 1, /* do not try again */
+    ack_failed_tmp = 2, /* temporary failed , try again */
+    ack_buffered = 3
 };
 
 /*
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.