[REPOST] [PATCH] emi2 reconnection behaviour

"Angel Fradejas" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Not much feedback on this one... (apart from Oded ;-) Don't you guys think
this would be a nice fix to have on CVS?

It would be nice to hear from the ones using EMI2 in a production
environment.

Angel.


-----Mensaje original-----
De: [email protected] [mailto:[email protected]]En
nombre de Angel Fradejas
Enviado el: lunes 9 de septiembre de 2002 11:30
Para: Kannel Developers
Asunto: [PATCH] emi2 reconnection behaviour


Hi all,

Attached is a patch to change the current behaviour of EMI2 driver when
handling connection errors.
I'm making EMI2 driver consistent with SMPP and SM/ASI behaviour and
configuration directives, while trying to fix a couple of things.

This is what the patch changes:

1) Removes "retry" smsc config directive for EMI2. It always assumes
reconnection, as the rest of drivers.
2) Adds a "reconnect-delay" directive, as SMPP and SM/ASI drivers: optional
time between attemps in seconds. It defaults to 10 seconds.

The reason for this changes (apart from making all drivers consistent), is
that current EMI2 handling of reconnection attempts is a mess.
Let me explain why:

1) It defaults to not retrying reconnection. That means that when you start
bearerbox, if a single EMI2 driver fails, the whole bearerbox refuses to
start. This is not acceptable for production use.

2) When it tries a reconnection (other than first time remember), it doubles
the time between attempts, until it reaches a fixed value. If you have
retry=yes it will grow until 64 minutes (!!!) and then settles on 60 minutes
(too much for production use).
Weirdly, if you have retry=no, it will also try to reconnect, but the time
between attemps grows only until 10 minutes.

Please, let me know comments and votes on this patch.

Thank you all.

Angel Fradejas
Mediafusión España, S.A.
[email protected]
www.mediafusion.es
Tel. +34 91 252 32 00
Fax  +34 91 572 27 08
emi2_reconnect.patch (application/octet-stream, 5 KB)
Index: doc/userguide/userguide.xml
===================================================================
RCS file: /home/cvs/gateway/doc/userguide/userguide.xml,v
retrieving revision 1.193
diff -u -r1.193 userguide.xml
--- doc/userguide/userguide.xml	8 Sep 2002 22:35:04 -0000	1.193
+++ doc/userguide/userguide.xml	9 Sep 2002 09:27:02 -0000
@@ -2310,12 +2310,12 @@
         use this variable. (optional)
      </entry></row>
 
-    <row><entry><literal>retry</literal></entry>
-      <entry><literal>boolean</literal></entry>
+    <row><entry><literal>reconnect-delay</literal></entry>
+      <entry><literal>number</literal></entry>
       <entry valign=bottom>
-        Assuming that kannel is well configured and we had one sucessful
-	connection, if retry is true, kannel will always retry the connection
-	even if some related error ocur.
+      Optional the time between attemps to connect an ESME to an SMSC 
+      having failed to connect initating or during a session. 
+		The default is 10 seconds.
      </entry></row>
 
     <row><entry><literal>my-number</literal></entry>
Index: gw/smsc/smsc_emi2.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_emi2.c,v
retrieving revision 1.2
diff -u -r1.2 smsc_emi2.c
--- gw/smsc/smsc_emi2.c	4 Sep 2002 17:08:52 -0000	1.2
+++ gw/smsc/smsc_emi2.c	9 Sep 2002 09:27:02 -0000
@@ -27,13 +27,14 @@
 #include "dlr.h"
 
 #define EMI2_MAX_TRN 100
+#define EMI2_RECONNECT_DELAY       10.0
 
 typedef struct privdata {
     Octstr	*name;
     List	*outgoing_queue;
     long	receiver_thread;
     long	sender_thread;
-    int		retry;	  	/* Retry always to connect to smsc */
+    long    reconnect_delay;
     int		shutdown;	  /* Internal signal to shut down */
     int		listening_socket; /* File descriptor */
     int		send_socket;
@@ -213,33 +214,22 @@
 	    privdata->alt_port != 0;
 
     wait = 0;
-    alt_host = -1; /* to avoid waiting in first cicle */
+    alt_host = do_alt_host ? 1 : 0;
 
     mutex_lock(conn->flow_mutex);
     conn->status = SMSCCONN_RECONNECTING;
     mutex_unlock(conn->flow_mutex);
     while (!privdata->shutdown) {
-	/* Change status only if the first attempt to form a
-	 * connection fails, as it's possible that the SMSC closed the
-	 * connection because of idle timeout and a new one will be
-	 * created quickly. */
-	if (wait) {
-	    while ((msg = list_extract_first(privdata->outgoing_queue))) {
-		bb_smscconn_send_failed(conn, msg,
-					SMSCCONN_FAILED_TEMPORARILY);
-	    }
-	    if(alt_host == 0) {
-		info(0, "EMI2[%s]: waiting for %d %s before trying to "
-			    "connect again", octstr_get_cstr(privdata->name), 
-			    (wait < 60 ? wait : wait/60), 
-			    (wait < 60 ? "seconds" : "minutes"));
-		gwthread_sleep(wait);
-		wait = wait > (privdata->retry ? 3600 : 600) ?
-		    (privdata->retry ? 3600 : 600) : wait * 2;
-	    }
-	}
-	else
-	    wait = 15; 
+    while ((msg = list_extract_first(privdata->outgoing_queue))) {
+        bb_smscconn_send_failed(conn, msg,
+                                SMSCCONN_FAILED_TEMPORARILY);
+    }
+    if(alt_host == 0) {
+        error(0, "EMI2[%s]: Couldn't connect to SMS center (retrying in %ld seconds).",
+              octstr_get_cstr(privdata->name), privdata->reconnect_delay);
+        gwthread_sleep(privdata->reconnect_delay);
+        continue;
+    }
 
 	if(alt_host != 1) {
 	    info(0, "EMI2[%s]: connecting to Primary SMSC", 
@@ -280,15 +270,11 @@
 	    if (result == -2) {
 		/* Are SMSCs going to return any temporary errors? If so,
 		 * testing for those error codes should be added here. */
-		error(0, "EMI2[%s]: Server rejected our login, giving up",
+		error(0, "EMI2[%s]: Server rejected our login",
 		      octstr_get_cstr(privdata->name));
 		conn_destroy(server);
-		if(! privdata->retry)  {
-		    conn->why_killed = SMSCCONN_KILLED_WRONG_PASSWORD;
-		    return NULL;
-		} else
-		    continue;
-	    }
+		continue;
+		}
 	    else if (result == 0) {
 		error(0, "EMI2[%s]: Got no reply to login attempt "
 		      "within 30 s", octstr_get_cstr(privdata->name));
@@ -1586,9 +1572,9 @@
     privdata->npid = cfg_get(cfg, octstr_imm("notification-pid"));
     privdata->nadc = cfg_get(cfg, octstr_imm("notification-addr"));
     
-    cfg_get_bool(&privdata->retry, cfg, octstr_imm("retry"));
-    if(privdata->retry < 0) 
-	privdata->retry = 0;
+    if (cfg_get_integer(&privdata->reconnect_delay, cfg, 
+                        octstr_imm("reconnect-delay")) == -1)
+        privdata->reconnect_delay = EMI2_RECONNECT_DELAY;
 
     if ( (privdata->username == NULL && privdata->my_number == NULL)
          || cfg_get_integer(&keepalive, cfg, octstr_imm("keepalive")) < 0)
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.72
diff -u -r1.72 cfg.def
--- gwlib/cfg.def	6 Sep 2002 12:07:58 -0000	1.72
+++ gwlib/cfg.def	9 Sep 2002 09:27:02 -0000
@@ -206,7 +206,6 @@
     OCTSTR(appname)
     OCTSTR(ussdc)
     OCTSTR(session-length)
-    OCTSTR(retry)
     OCTSTR(my-number)
     OCTSTR(sms-center)
     OCTSTR(source-addr-ton)
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.