Ensure that test_statestore always uses free ports
Ensure that test_statestore always uses free ports

test_statestore.py needs a lot of ports to run subscriber servers
on. before this patch, we'd find a free port by binding to port 0,
finding what port the OS actually used, and closing the original socket
before passing that port to the actual server to start up. However, this
was obviously racy if some other process is also looking for a free
port at the same time.

This patch moves the bind logic into the Thrift server socket itself, so
that there's no close->open race window between binding to the port and
actually wanting to use it.

I wasn't able to reproduce the issue on my local machine, but this
diagnosis fits the problems we've seen.

Change-Id: Idfbbe71f596ff5a7c3f4ff33b5edd565648d8e59
Reviewed-on: http://gerrit.cloudera.org:8080/754
Reviewed-by: Dan Hecht <20ebd99959f0f6e5dcb0fc319b4d8ef53a16b5fb@cloudera.com>
Tested-by: Internal Jenkins

cloudera/Impala,michaelhkw/incubator-impala,michaelhkw/incubator-impala,michaelhkw/incubator-impala,cloudera/Impala,michaelhkw/incubator-impala,cloudera/Impala,cloudera/Impala,michaelhkw/incubator-impala,cloudera/Impala,michaelhkw/incubator-impala,michaelhkw/incubator-impala,cloudera/Impala,cloudera/Impala