public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: John Freeman <johnf@optimation.com.au>
To: Brad Midgley <bmidgley@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: Intermittent "Address already in use" error
Date: Tue, 28 Jul 2009 18:36:30 +1000	[thread overview]
Message-ID: <30761901.1248770182239.JavaMail.root@safetgram> (raw)
In-Reply-To: <5111969.1248454126654.JavaMail.root@safetgram>

Brad Midgley wrote:
> John,
> 
>> 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)
> 
> Is the error appearing when you want to rebind a short time after it
> was used? Maybe you need to setsockopt SO_REUSEADDR just like you
> would if you wanted to quickly rebind a tcp serversocket.

Brad,

Thanks for the suggestion.  At first sight, that seemed like a possible cause. 
However, further testing shows that I can make another attempt a few seconds 
(limited by the speed of my fingers) after the socket has been closed, and that 
it is usually successful.

When it fails, /sys/class/bluetooth/sco contains:

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

where "A2:C7:07:83:15:00" matches addr1 in the code above.  Normally, content 
appears in /sys/class/bluetooth/sco at the point of bind(), is modified slightly 
by listen(), then disappears on close of the Listener socket.

Once it gets into this state, all further attempts to bind fail with "Address 
already in use" ... until I reboot.

I haven't been able to pin down the exact circumstances that trigger the problem 
other than that it seems more likely to occur following a program run that fails 
with an unhandled exception.  That is, it seems like things aren't cleaned-up 
correctly sometimes. Unfortunately, I can't make it happen at will.

Any more ideas?

John.



  parent reply	other threads:[~2009-07-28  8:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=30761901.1248770182239.JavaMail.root@safetgram \
    --to=johnf@optimation.com.au \
    --cc=bmidgley@gmail.com \
    --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