[GH-ISSUE #56] Crashing when receiving high load of messages #49

Closed
opened 2026-02-28 01:22:56 +03:00 by kerem · 4 comments
Owner

Originally created by @mandric on GitHub (Oct 30, 2012).
Original GitHub issue: https://github.com/ushahidi/SMSSync/issues/56

Hello, I can replicate a crash on SMSSync in the emulator just by using telnet and sms send with multiple messages (50+) then smsync crashes and I get the Force Quit message from Android (http://cl.ly/image/0F3A3w1p3M2w). I'm using 1.1.9 because i need to support Android 2.x. Here's the trace I get and the point in the code from the trace. Let me know if you have any thoughts on this, thanks!

E/AndroidRuntime(  473): FATAL EXCEPTION: main
E/AndroidRuntime(  473): java.lang.RuntimeException: Unable to start receiver org.addhen.smssync.receivers.SmsReceiver: java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks
E/AndroidRuntime(  473):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805)
E/AndroidRuntime(  473):    at android.app.ActivityThread.access$2400(ActivityThread.java:117)
E/AndroidRuntime(  473):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
E/AndroidRuntime(  473):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  473):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  473):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(  473):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  473):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  473):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(  473):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(  473):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  473): Caused by: java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks
E/AndroidRuntime(  473):    at android.net.wifi.WifiManager$WifiLock.acquire(WifiManager.java:908)
E/AndroidRuntime(  473):    at org.addhen.smssync.services.SmsReceiverService.beginStartingService(SmsReceiverService.java:477)
E/AndroidRuntime(  473):    at org.addhen.smssync.receivers.SmsReceiver.onReceive(SmsReceiver.java:43)
E/AndroidRuntime(  473):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)
E/AndroidRuntime(  473):    ... 10 more
W/ActivityManager(   61):   Force finishing activity org.addhen.smssync/.MessagesTabActivity
 29 /**
 30  * This class handles SMS broadcast receiver.
 31  * 
 32  * @author eyedol
 33  */
 34 
 35 public class SmsReceiver extends BroadcastReceiver {
 36 
 37     @Override
 38     public void onReceive(Context context, Intent intent) {
 39 
 40         intent.setClass(context, SmsReceiverService.class);
 41         intent.putExtra("result", getResultCode());
 42 
 43         SmsReceiverService.beginStartingService(context, intent);
 44     }
 45 
 46 }
Originally created by @mandric on GitHub (Oct 30, 2012). Original GitHub issue: https://github.com/ushahidi/SMSSync/issues/56 Hello, I can replicate a crash on SMSSync in the emulator just by using telnet and `sms send` with multiple messages (50+) then smsync crashes and I get the Force Quit message from Android (http://cl.ly/image/0F3A3w1p3M2w). I'm using 1.1.9 because i need to support Android 2.x. Here's the trace I get and the point in the code from the trace. Let me know if you have any thoughts on this, thanks! ``` E/AndroidRuntime( 473): FATAL EXCEPTION: main E/AndroidRuntime( 473): java.lang.RuntimeException: Unable to start receiver org.addhen.smssync.receivers.SmsReceiver: java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks E/AndroidRuntime( 473): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805) E/AndroidRuntime( 473): at android.app.ActivityThread.access$2400(ActivityThread.java:117) E/AndroidRuntime( 473): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981) E/AndroidRuntime( 473): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 473): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 473): at android.app.ActivityThread.main(ActivityThread.java:3683) E/AndroidRuntime( 473): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 473): at java.lang.reflect.Method.invoke(Method.java:507) E/AndroidRuntime( 473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) E/AndroidRuntime( 473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) E/AndroidRuntime( 473): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 473): Caused by: java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks E/AndroidRuntime( 473): at android.net.wifi.WifiManager$WifiLock.acquire(WifiManager.java:908) E/AndroidRuntime( 473): at org.addhen.smssync.services.SmsReceiverService.beginStartingService(SmsReceiverService.java:477) E/AndroidRuntime( 473): at org.addhen.smssync.receivers.SmsReceiver.onReceive(SmsReceiver.java:43) E/AndroidRuntime( 473): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794) E/AndroidRuntime( 473): ... 10 more W/ActivityManager( 61): Force finishing activity org.addhen.smssync/.MessagesTabActivity ``` ``` 29 /** 30 * This class handles SMS broadcast receiver. 31 * 32 * @author eyedol 33 */ 34 35 public class SmsReceiver extends BroadcastReceiver { 36 37 @Override 38 public void onReceive(Context context, Intent intent) { 39 40 intent.setClass(context, SmsReceiverService.class); 41 intent.putExtra("result", getResultCode()); 42 43 SmsReceiverService.beginStartingService(context, intent); 44 } 45 46 } ```
kerem closed this issue 2026-02-28 01:22:56 +03:00
Author
Owner

@mandric commented on GitHub (Oct 30, 2012):

Hrm I think I have a patch... this seems to fix it for me.

--- a/src/org/addhen/smssync/services/SmsReceiverService.java
+++ b/src/org/addhen/smssync/services/SmsReceiverService.java
@@ -450,6 +450,17 @@ public class SmsReceiverService extends Service {
         return msgs;
     }

+   synchronized protected static WifiManager.WifiLock getWifiLock(Context context) {
+        // keep wifi alive
+        if (wifilock == null) {
+            WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+            wifilock = manager.createWifiLock(CLASS_TAG);
+            wifilock.setReferenceCounted(true);
+        }
+
+        return wifilock;
+    }
+
     /**
      * Start the service to process the current event notifications, acquiring
      * the wake lock before returning to ensure that the service will run.
@@ -467,14 +478,9 @@ public class SmsReceiverService extends Service {
                 mStartingService.setReferenceCounted(false);
             }

-            // keep wifi alive
-            if (wifilock == null) {
-                WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
-                wifilock = manager.createWifiLock(CLASS_TAG);
-            }
-
             mStartingService.acquire();
-            wifilock.acquire();
+            if (!getWifiLock(context).isHeld()) 
+                getWifiLock(context).acquire();
             context.startService(intent);
         }
     }
<!-- gh-comment-id:9924561 --> @mandric commented on GitHub (Oct 30, 2012): Hrm I think I have a patch... this seems to fix it for me. ``` --- a/src/org/addhen/smssync/services/SmsReceiverService.java +++ b/src/org/addhen/smssync/services/SmsReceiverService.java @@ -450,6 +450,17 @@ public class SmsReceiverService extends Service { return msgs; } + synchronized protected static WifiManager.WifiLock getWifiLock(Context context) { + // keep wifi alive + if (wifilock == null) { + WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + wifilock = manager.createWifiLock(CLASS_TAG); + wifilock.setReferenceCounted(true); + } + + return wifilock; + } + /** * Start the service to process the current event notifications, acquiring * the wake lock before returning to ensure that the service will run. @@ -467,14 +478,9 @@ public class SmsReceiverService extends Service { mStartingService.setReferenceCounted(false); } - // keep wifi alive - if (wifilock == null) { - WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); - wifilock = manager.createWifiLock(CLASS_TAG); - } - mStartingService.acquire(); - wifilock.acquire(); + if (!getWifiLock(context).isHeld()) + getWifiLock(context).acquire(); context.startService(intent); } } ```
Author
Owner

@eyedol commented on GitHub (Oct 31, 2012):

@mandric Are you sending the 50+ messages at a goal? And oh 2.x.x should support Android 2.x and above. It only dropped support for 1.6. I'll try and reproduce the issue and patch the code with your fix.

<!-- gh-comment-id:9933111 --> @eyedol commented on GitHub (Oct 31, 2012): @mandric Are you sending the 50+ messages at a goal? And oh 2.x.x should support Android 2.x and above. It only dropped support for 1.6. I'll try and reproduce the issue and patch the code with your fix.
Author
Owner

@mandric commented on GitHub (Oct 31, 2012):

Pretty sure I had the same issue whether I setup a syncurl or not. I'm not sure what you mean by goal.

I should start using the 2.x branch then, I had trouble compiling it with that target. e.g. android update project --target "android-10" -p . I'll try again...

<!-- gh-comment-id:9936535 --> @mandric commented on GitHub (Oct 31, 2012): Pretty sure I had the same issue whether I setup a syncurl or not. I'm not sure what you mean by goal. I should start using the 2.x branch then, I had trouble compiling it with that target. e.g. `android update project --target "android-10" -p .` I'll try again...
Author
Owner

@eyedol commented on GitHub (Nov 1, 2012):

@mandric I meant 50 messages at a time?

<!-- gh-comment-id:9967217 --> @eyedol commented on GitHub (Nov 1, 2012): @mandric I meant 50 messages at a time?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SMSSync#49
No description provided.