Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:59:35+00:00 2026-06-15T19:59:35+00:00

I’m running into a problem using Bluetooth in my app. It seems that after

  • 0

I’m running into a problem using Bluetooth in my app. It seems that after 28 BluetoothSocket/BluetoothServerSockets have been created, all of the ports are taken. The sockets don’t need to be opened simultaneously, it’s just 28 sockets since Bluetooth was enabled.

This can be reproduced using the BluetoothChat sample provided in the Android Samples. Simply open and close the app 15 times (the app creates 2 sockets each time). On the 15th time, it will crash and will continue to crash until you disable and then re-enable Bluetooth:

12-06 18:43:58.177: E/BluetoothSocket(18530): bindListen, fail to get port number, exception: java.io.IOException: read failed, socket might closed, read ret: -1
12-06 18:43:58.193: E/BluetoothChatService(18530): Socket Type: Insecurelisten() failed
12-06 18:43:58.193: E/BluetoothChatService(18530): java.io.IOException: Error: -1
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:1035)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.bluetooth.BluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord(BluetoothAdapter.java:982)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.example.android.BluetoothChat.BluetoothChatService$AcceptThread.<init>(BluetoothChatService.java:280)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.example.android.BluetoothChat.BluetoothChatService.start(BluetoothChatService.java:119)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.example.android.BluetoothChat.BluetoothChat.onResume(BluetoothChat.java:131)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.Activity.performResume(Activity.java:5182)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.os.Looper.loop(Looper.java:137)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.ActivityThread.main(ActivityThread.java:5039)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at java.lang.reflect.Method.invokeNative(Native Method)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at java.lang.reflect.Method.invoke(Method.java:511)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at dalvik.system.NativeStart.main(Native Method)

Is there any way to free the ports after the socket is closed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:59:36+00:00Added an answer on June 15, 2026 at 7:59 pm

    I can verify this behavior on device that I have here; although the number of times required to crash in the same way varies by device (I think 20-25 times were required on the Galaxy Nexus running 4.2) so the available number of port handles seems to vary. I can also contribute the information that the issue is not a memory leak in the sample app (or your app for that matter) as all instances of BluetoothSocket have been released and closed by Dalvik. The steps listed here only tests the issue on BluetoothServerSocket, so its unclear if the problem is specifically related to that, though it seems unlikely.

    At least on my devices, you cannot even start the app up again until toggling the Bluetooth adapter’s status, so the problem is definitely in the underlying management of the connections on the stack.

    I would file a bug with steps to reproduce here http://b.android.com and I’d be happy to upvote it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have been unable to fix a problem with Java Unicode and encoding. The
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.