Re: [Devel] mmsbox_mm1 stability

2010-08-04 Thread Paul Bagyenda
Thanks Piotr

Patch applied. 
On Aug 04, 2010, at 08:55, Piotr Isajew wrote:

> Hi,
> 
> I'm using mmsbox-mm1 very intensively for outgoing messages. It's
> great, but I've noticed some deadlock/blocking problems when using it
> under heavy load. Those are mostly related to situations when GPRS
> connection dies, or pppd process is alive, but stops transmitting
> packets. In some situations handle_mm1 thread leaves zombie pppd
> processes. 
> 
> I'm attaching small patch that solved most of those problems for
> me. I'm however new to mbuni architecture so I'm not sure if it
> doesn't damage something else.
> 
> Piotr
> ___
> Devel mailing list
> Devel@mbuni.org
> http://lists.mbuni.org/mailman/listinfo/devel

___
Devel mailing list
Devel@mbuni.org
http://lists.mbuni.org/mailman/listinfo/devel


[Devel] mmsbox_mm1 stability

2010-08-03 Thread Piotr Isajew
Hi,

I'm using mmsbox-mm1 very intensively for outgoing messages. It's
great, but I've noticed some deadlock/blocking problems when using it
under heavy load. Those are mostly related to situations when GPRS
connection dies, or pppd process is alive, but stops transmitting
packets. In some situations handle_mm1 thread leaves zombie pppd
processes. 

I'm attaching small patch that solved most of those problems for
me. I'm however new to mbuni architecture so I'm not sure if it
doesn't damage something else.

Piotr
--- mmsbox_mm1.c.orig   2010-05-19 08:33:05.769118569 +0200
+++ mmsbox_mm1.c2010-07-28 17:49:51.015190352 +0200
@@ -359,7 +359,7 @@
 {
  /* stop smsc, start GPRS, transact, stop GPRS, start SMSC. And so on. */
  MM1Request *r;
- 
+
  mms_info(0, "mmsbox-mm1", NULL, "handle_mm1 started");
  mm1->sender_alive++;
  while ((r = gwlist_consume(mm1->requests)) != NULL) {
@@ -512,10 +512,28 @@
   octstr_destroy(body);
   octstr_destroy(ms);
   mms_destroy(m);
- } while (gwlist_len(mm1->requests) > 0 && 
+  r = NULL;
+  pid_t wp;
+  int st;
+  wp = waitpid(pid, &st, WNOHANG);
+  if(wp == pid && WIFEXITED(st)) {
+mms_info(0, "mmsbox-mm1", NULL, "GPRS pid (%d) appears to be 
dead - quitting loop", pid);
+goto after_gprs_dead;
+  }
+ } while (gwlist_len(mm1->requests) > 0 &&
   (r = gwlist_consume(mm1->requests)) != NULL);
  
  kill_gprs:
+ if(r != NULL) {
+   if(r->waiter_exists) {
+ pthread_mutex_unlock(&r->mutex);
+ pthread_cond_signal(&r->cond);
+   } else{
+ gw_free(r);
+   }
+   
+   
+ }
  if (pid > 0) { /* stop GPRS, restart SMSC connection. */
   int xkill, status;
   pid_t wpid;
@@ -532,7 +550,7 @@
   } while (1);
   gwthread_sleep(2);
  }
-
+ after_gprs_dead:
  if (mm1->smsc_on) {
   system(octstr_get_cstr(mm1->smsc_on));
   gwthread_sleep(5);
@@ -610,10 +628,13 @@
  curl_easy_setopt(cl, CURLOPT_WRITEFUNCTION, write_octstr_data);
  curl_easy_setopt(cl, CURLOPT_WRITEDATA, s);
  curl_easy_setopt(cl, CURLOPT_NOSIGNAL, 1L);
+ curl_easy_setopt(cl, CURLOPT_TIMEOUT, 120L);
+ curl_easy_setopt(cl, CURLOPT_FORBID_REUSE, 1L);
+ curl_easy_setopt(cl, CURLOPT_CONNECTTIMEOUT, 40L);
 
  h = curl_slist_append(h, "Accept: */*");
  if (body) { /* POST. */
- h = curl_slist_append(h, "Content-Type: 
application/vnd.wap.mms-message");  
+ h = curl_slist_append(h, "Content-Type: 
application/vnd.wap.mms-message");
  curl_easy_setopt(cl, CURLOPT_POSTFIELDS, octstr_get_cstr(body));
  curl_easy_setopt(cl, CURLOPT_POSTFIELDSIZE, octstr_len(body));
  }
@@ -635,7 +656,7 @@
 
 #include 
 
-#define MAX_GPRS_WAIT 60
+#define MAX_GPRS_WAIT 80
 #define GPRS_POLL  5
 static long start_gprs(Octstr *cmd, Octstr *pid_cmd)
 {
@@ -661,6 +682,14 @@
   WIFEXITED(status))
 return -1;
  } while (GPRS_POLL*ct++ < MAX_GPRS_WAIT);
+ /* Timed out, but still need to wait for child pid, as
+ start-gprs script is still running and we don't need a
+ zombie */
+ pid_t rpid;
+ int st;
+
+ rpid = waitpid(pid, &st, 0);
+ mms_info(0, "mmsbox-mm1", NULL, "pid %d terminated", pid);
  return -1;
 } else if (pid == 0) { /* child. */
  List *l = octstr_split_words(cmd);
___
Devel mailing list
Devel@mbuni.org
http://lists.mbuni.org/mailman/listinfo/devel