public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: John Freeman <johnf@optimation.com.au>
To: linux-bluetooth@vger.kernel.org
Subject: Intermittent "Address already in use" error
Date: Fri, 24 Jul 2009 20:08:15 +1000	[thread overview]
Message-ID: <1346165.1248430092866.JavaMail.root@safetgram> (raw)

I am developing an application that is similar to a Hands-free service
written in python.

 From time to time, I encounter an "Address already in use" error when
attempting to bind a socket to a particular local adapter.  The python
code looks like:

    Listener = BluetoothSocket(SCO)
    Listener.bind((addr1, ))
    Listener.listen(1)

strace shows this as:

    3328  socket(PF_BLUETOOTH, SOCK_SEQPACKET, 2)               = 5
    3328  bind(5, {sa_family=AF_BLUETOOTH, 
sa_data="\xa2\xc7\x07\x83\x15\x00\x13\xad\x76\x2d\xf4\xf2\x42\x09"...}, 8) = 0
    3328  listen(5, 1)                                          = 0

Subsequently, in a separate python thread (is this significant?), I issue:

    sock, whence = Listener.accept()

strace shows this as:

    3343  accept(5,  <unfinished ...>
    ...
    3343  accept(5,  <unfinished ...>
    ...
    3343  <... accept resumed> {sa_family=AF_BLUETOOTH, 
sa_data="\x4e\xe4\xec\xfd\x1d\x00\xb4\x3b\x82\x04\x20\x04\xbb\xb7"...}, [8]) = 10

After many send() and recv() calls on the socket, it is closed.

Sometimes, the accept-recv-send-close cycle is repeated a number of times.

At the conclusion of the program the Listener socket is always closed.
Because, initially, it looked like the problem was related to not
closing this socket, I added logging so that I could be absolutely
sure it had been closed.

Now that you understand what the program does, we can get down to
explaining the problem.

I can run the program muliple times with no error, but occasionally
the

    Listener.bind((addr1, ))

raises a Bluetooth error (98, 'Address already in use')

When this happens, I find that there is a file /sys/class/bluetooth/sco
that contains:

    A2:C7:07:83:15:00 00:00:00:00:00:00 4

When we don't experience this problem, this file doesn't exist or is empty.

The contents of the file correspond to the bind() call, but I would
expect this to be cleaned-up on a close() of the listener.  Usually it
is, but sometimes not.  There are no obvious correlations with external
events as far as I can tell.

The problem persists as long as /sys/class/bluetooth/sco is non-empty,
and I have not discovered any way to continue other than to reboot,
which causes the file to disappear.

Any pointers on where to look next would be greatly appreciated.

             reply	other threads:[~2009-07-24 10:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 10:08 John Freeman [this message]
2009-07-24 16:47 ` Intermittent "Address already in use" error Brad Midgley
     [not found] ` <5111969.1248454126654.JavaMail.root@safetgram>
2009-07-28  8:36   ` John Freeman
2009-07-28 17:31     ` Brad Midgley
     [not found]     ` <27042187.1248802358830.JavaMail.root@safetgram>
2009-07-30  9:17       ` John Freeman
2009-07-30 23:23         ` Brad Midgley
     [not found]         ` <2648525.1248996255356.JavaMail.root@safetgram>
2009-07-31  1:06           ` John Freeman
     [not found]           ` <33459247.1249002454978.JavaMail.root@safetgram>
2009-07-31  6:36             ` John Freeman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1346165.1248430092866.JavaMail.root@safetgram \
    --to=johnf@optimation.com.au \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox