IndexError raising CannotBindAddress error starting bzr serve

Bug #286871 reported by Andrew Cowie
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Unassigned

Bug Description

`bzr serve ` worked with bzr 1.7; it doesn't with bzr 1.8.

# bzr serve
bzr: ERROR: exceptions.IndexError: tuple index out of range

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 849, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 795, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 495, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/usr/lib/python2.5/site-packages/bzrlib/builtins.py", line 3922, in run
    smart_server = server.SmartTCPServer(t, host=host, port=port)
  File "/usr/lib/python2.5/site-packages/bzrlib/smart/server.py", line 78, in __init__
    raise errors.CannotBindAddress(host, port, message)
  File "/usr/lib/python2.5/site-packages/bzrlib/errors.py", line 2853, in __init__
    orig_error=orig_error[1])
IndexError: tuple index out of range

bzr 1.8 on python 2.5.2 (linux2)
arguments: ['/usr/bin/bzr', 'serve']
encoding: 'ANSI_X3.4-1968', fsenc: 'ANSI_X3.4-1968', lang: None
plugins:
  launchpad /usr/lib/python2.5/site-packages/bzrlib/plugins/launchpad [unknown]
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.
epsilon ~ #

Help?

AfC

Tags: easy hpss
Revision history for this message
Andrew Cowie (afcowie) wrote :

I should mention that I tried different --port arguments etc just to make sure. All no joy. We were forced to downgrade back to bzr 1.7.1

AfC

Revision history for this message
Martin Pool (mbp) wrote :

I think the underlying problem is that (as the traceback suggests) it cannot bind the listening socket. Could it be that 'bzr serve' or something else is already using port 4155 on this machine?

In both 1.8 and trunk I can run 'bzr serve' and get a reasonable error if it fails to bind the address because it's in use.

However, the CannotBindAddress constructor does seem strange to be indexing the original error this way. I'm not sure why this needs to be a special error class.

Changed in bzr:
status: New → Incomplete
importance: Undecided → Medium
status: Incomplete → Confirmed
Revision history for this message
Andrew Cowie (afcowie) wrote :

Uh no, nothing is already 4155. But more to the point, since the same thing happened when I tried it with $random other ports, I'm not really sure why CannotBindAddress is occurring. My guess is that that in turn is proxy for some other problem, but I wouldn't have the faintest idea where to even begin looking to articulate that.

AfC

Revision history for this message
Andrew Bennetts (spiv) wrote :

Something a bit funny is going on indeed. On my Ubuntu intrepid laptop doing "bzr serve" in two terminals triggers a normal error, not a traceback:

$ bzr serve
bzr: ERROR: Cannot bind address "None:4155": Address already in use.

My guess is that the socket error that is triggering the error is not an "Address already in use" error, although what else it might be I don't know. What happens if you replace the "raise errors.CannotBindAddress(...)" line with a plain "raise"? (i.e. reraise the original exception)

Revision history for this message
Andrew Bennetts (spiv) wrote :

Ah, the main change to this code since 1.7 is that it attempts to listen on IPv6 if possible, as well as IPv4.

The relevant patch hunk is:

@@ -59,13 +62,18 @@
         from socket import error as socket_error
         self._socket_error = socket_error
         self._socket_timeout = socket_timeout
- self._server_socket = socket.socket()
+ addrs = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
+ socket.SOCK_STREAM, 0, socket.AI_PASSIVE)[0]
+
+ (family, socktype, proto, canonname, sockaddr) = addrs
+
+ self._server_socket = socket.socket(family, socktype, proto)
         # SO_REUSERADDR has a different meaning on Windows
         if sys.platform != 'win32':
             self._server_socket.setsockopt(socket.SOL_SOCKET,
                 socket.SO_REUSEADDR, 1)
         try:
- self._server_socket.bind((host, port))
+ self._server_socket.bind(sockaddr)
         except self._socket_error, message:
             raise errors.CannotBindAddress(host, port, message)
         self._sockname = self._server_socket.getsockname()

So I guess attempting to bind to an IPv6 port is raising an unexpected sort of socket error on your system?

If you can tell us which exception is being raised, we can probably fix this to just fall back to the IPv4-only code when it occurs.

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 286871] Re: IndexError raising CannotBindAddress error starting bzr serve

On Tue, Oct 21, 2008 at 10:01 PM, Andrew Bennetts
<email address hidden> wrote:
> Ah, the main change to this code since 1.7 is that it attempts to listen
> on IPv6 if possible, as well as IPv4.

Yes, you can get things like this on machines that eg know about ipv6
but don't have any ipv6 addresses. I think distcc has something to
work around this.

If I'd reviewed that change I think I would have suggested listening
only on ipv4 by default unless the user specifically asked for it with
--port, as for most users today it will only cause trouble.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Martin Pool (mbp) wrote :

If my theory is true, Andrew may be able to work around the problem by
using --port to explicitly give an ipv4 host address, eg

  --port 127.0.0.1:12345

Revision history for this message
Andrew Cowie (afcowie) wrote :

I'll try the workaround presently, but off hand I can tell you that the services on that server are only set to listen on normal IP addresses. We don't waste time with IPv6 stuff.

AfC

Revision history for this message
Andrew Cowie (afcowie) wrote :

Yes, specifying

--port 0.0.0.0:4155

allowed it to work.

AfC

Revision history for this message
Martin Pool (mbp) wrote :

On Wed, Oct 22, 2008 at 1:17 PM, Andrew Cowie
<email address hidden> wrote:
> I'll try the workaround presently, but off hand I can tell you that the
> services on that server are only set to listen on normal IP addresses.
> We don't waste time with IPv6 stuff.

OK, thanks for confirming that.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

We should be specifying AI_ADDRCONFIG - that way getaddrinfo() only returns addresses that can actually be used. Unfortunately, this doesn't appear to exist on Windows.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Re-open if I'm wrong but this has been fixed in 2.0rc1

Changed in bzr:
milestone: none → 2.0rc1
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.