public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* Intermittent "Address already in use" error
@ 2009-07-24 10:08 John Freeman
  2009-07-24 16:47 ` Brad Midgley
       [not found] ` <5111969.1248454126654.JavaMail.root@safetgram>
  0 siblings, 2 replies; 8+ messages in thread
From: John Freeman @ 2009-07-24 10:08 UTC (permalink / raw)
  To: linux-bluetooth

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-07-31  6:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-24 10:08 Intermittent "Address already in use" error John Freeman
2009-07-24 16:47 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox