apt-avahi-discover can take a long time when the destination service port is blocked
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
squid-deb-proxy (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
When trying to use apt I noticed that actions that required the proxy were taking a long time to complete. I tracked that down to the squid-deb-
Current output:
$ time /usr/share/
avahi-browse output:
<snipped>
no timeout set, using default '2'
error: uncaptured python exception, closing channel <AptAvahiClient> ('192.168.86.60', 127): 9223372036854775807 (<class 'socket.
sorted hosts: '[<AptAvahiClient> ('192.168.86.30', 8000): 0.00731706619263, <AptAvahiClient> ('10.113.100.1', 8000): 0.00739908218384, <AptAvahiClient> ('fd42:
http://
/usr/share/
Here 192.168.86.30 is the "localhost", which also runs lxd (thus the 10.113.1001 address) and the squid-deb-proxy service. My laptop is 192.168.86.60 and also runs its own squid-deb-proxy service.
My laptop (192.168.86.60) is firewalled, so although its own avahi-daemon contacted the other server (192.168.86.30) to announce the service, the other server can't really access it (thus the huge int for the "response" time.
Interrupting the calls led me to:
<snipped>
Traceback (most recent call last):
File "/usr/share/
address = get_proxy_
File "/usr/share/
asyncore.
File "/usr/lib/
poll_
File "/usr/lib/
r, w, e = select.select(r, w, e, timeout)
So what happens is that the asyncore.loop() call will hang until the sockets timeout.
I have tried a few things such as:
- setting default timeout to 1
- setting the socket.
inside AptAvahiClient before the connect call
but neither of the above worked.
What finally worked was to set asyncore.
Output with asyncore.
$ time /usr/share/
avahi-browse output:
<snipped>
no timeout set, using default '2'
sorted hosts: '[<AptAvahiClient> ('192.168.86.30', 8000): 0.00732398033142, <AptAvahiClient> ('10.113.100.1', 8000): 0.00736904144287, <AptAvahiClient> ('fd42:
http://
/usr/share/
So, around 1 seconds, way better.
I also tried using other values for count, here is a small table with timeout = 2 (the default):
count = 1 -> 1 second
count = 2 -> 3 seconds
count = 3 -> 5 seconds
count = 4 -> 7 seconds
count = 5 -> 9 seconds
count = 8 -> 15 seconds
count = 15 -> 29 seconds
For timeout = 5:
count = 1 -> 1 second
count = 2 -> 6 seconds
count = 3 -> 11 seconds
count = 4 -> 16 seconds
count = 5 -> 21 seconds
For the time measurements I ran the commands at least 5 times to check for any outliers, the few changes I saw there mostly corresponded to the timing variation from just the avahi-browse call [3].
It seems that the very first try "timeouts" pretty quick (under a second), but the following retries (if count > 1) do take the set timeout into account. Thus, for my tests, the actual timeout is around: ((timeout * (count -1)) + 1. Remember that the +1 comes from the avahi-browser in my environment, if it takes longer or shorter than that won't really affect (or be affected by) my proposed fix.
I'm attaching a patch that uses count=2 which should give a timeout pretty close to the one set by the user (or the default), but that might need additional review as I'm not sure what are the possible drawbacks from setting count to such a low value.
Additional info:
$cat /etc/os-release
NAME="Ubuntu"
VERSION="17.10 (Artful Aardvark)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 17.10"
VERSION_ID="17.10"
HOME_URL="https:/
SUPPORT_URL="https:/
BUG_REPORT_URL="https:/
PRIVACY_
VERSION_
UBUNTU_
$ apt-cache policy squid-deb-proxy
squid-deb-proxy:
Installed: 0.8.14
Candidate: 0.8.14
Version table:
*** 0.8.14 500
500 http://
500 http://
100 /var/lib/
[1] https:/
[2] https:/
[3] The "avahi-browse -kprtf _apt_proxy._tcp" command (called by apt-avahi-discover) runs in around 1 second most of the time, but it did take 3+ seconds a couple times.
The attachment "apt-avahi- discover_ timeout- fix.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.
[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]