title: android bluetooth connection fails after 489 successful connections
body: <p>unfortunately, I have some problems with android's bluetooth. For my test environment I use a Nexus 4 with Android 4.4.2.</p>
  
  <p>I have a Java Application on my PC, which uses bluecove in order to make a SPP connection as client. The programme is looking for a special service name and connects with my android phone. Afterwards it sends 72 bytes to my android phone and waits for an answer. When getting that answer the programme sleeps for 3 seconds and than starts again.</p>
  
  <p>On my android phone I have an application with background bluetooth listener which starts at boot. This application is based on BluetoothChat sample demo. When receiving bluetooth data I check incoming data and send back an answer.</p>
  
  <p>All that is working fine. But after 489 bluetooth connections the android app fails with following error snippet while PC-java-app is going on:</p>
  
  <pre><code>getBluetoothService() called with no BluetoothManagerCallback
  Shutting down VM
  threadid=1: thread exiting with uncaught exception (group=0x41b34ba8)
  FATAL EXCEPTION: main
  Process: de.tum.lme.diamantum:remote_blue, PID: 21567
  java.lang.NullPointerException: FileDescriptor must not be null
      at android.os.ParcelFileDescriptor.&lt;init&gt;(ParcelFileDescriptor.java:174)
      at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:905)
      at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:897)
      at android.bluetooth.IBluetooth$Stub$Proxy.createSocketChannel(IBluetooth.java:1355)
      at android.bluetooth.BluetoothSocket.bindListen(BluetoothSocket.java:349)
      at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:1055)
      at android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:976)
      at com.test.btconn.BluetoothHandling$AcceptThread.&lt;init&gt;(BluetoothHandling.java:449)
      at com.test.btconn.BluetoothHandling.start(BluetoothHandling.java:216)
      at com.test.btconn.BluetoothListenerService.setupBtSockets(BluetoothListenerService.java:330)
      at com.test.btconn.BluetoothListenerService.manageBtState(BluetoothListenerService.java:249)
      at com.test.btconn.BluetoothListenerService.setBtStateDisconnected(BluetoothListenerService.java:383)
      at com.test.btconn.BluetoothListenerService.access$5(BluetoothListenerService.java:378)
      at com.test.btconn.BluetoothListenerService$2.handleMessage(BluetoothListenerService.java:421)
  </code></pre>
  
  <p>So the app has a problem with the ParcelFileDescriptor, which is suddenly null. But why?</p>
  
  <p>All the described above also happens when changing pause-time on PC-java-app, using various data sizes for transmitting and using different smartphones. When using reflection "listenUsingRfcommWithServiceRecord" the same happens after 505 transmissions. Also using wakelock changes nothing. </p>
  
  <p>By the way, I got the same behaviour when using BluetoothChat sample. </p>
  
  <p>So, has anybody a hint, what happens?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>BluetoothServerSocket is closed after each connection and BluetoothSocket if bluetooth state is 3.</p>