All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Cc: linux-nfs@vger.kernel.org, Gil Amsalem <gil.amsalem@primarydata.com>
Subject: Re: [PATCH] Reduce the probability to get port collision when asking for secure port. port collision = same port allocated to 2 different clients trying to connect to the same address.
Date: Tue, 12 Jan 2016 17:06:52 -0500	[thread overview]
Message-ID: <20160112220652.GB8256@fieldses.org> (raw)
In-Reply-To: <1449559654-14766-2-git-send-email-tigran.mkrtchyan@desy.de>

Sorry for a slow response.

I'm confused.  You're worried about two pynfs instances binding to the
same local port at the same time?  The kernel should prevent that,
shouldn't it?

--b.

On Tue, Dec 08, 2015 at 08:27:34AM +0100, Tigran Mkrtchyan wrote:
> From: Gil Amsalem <gil.amsalem@primarydata.com>
> 
> Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
> ---
>  rpc/rpc.py | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/rpc/rpc.py b/rpc/rpc.py
> index 1a3ca38..8d88c62 100644
> --- a/rpc/rpc.py
> +++ b/rpc/rpc.py
> @@ -824,23 +824,19 @@ class ConnectionHandler(object):
>          defer.wait()
>          return pipe
>  
> -    def bindsocket(self, s, port=1):
> +    def bindsocket(self, s, start_port=1):
>          """Scan up through ports, looking for one we can bind to"""
>          # This is necessary when we need to use a 'secure' port
> -        using = port
> -        while 1:
> +        valid_ports = range(start_port, 1024)
> +        random.shuffle(valid_ports)
> +        for port in valid_ports:
>              try:
> -                s.bind(('', using))
> +                s.bind(('', port))
>                  return
>              except socket.error, why:
> -                if why[0] == errno.EADDRINUSE:
> -                    using += 1
> -                    if port < 1024 <= using:
> -                        # If we ask for a secure port, make sure we don't
> -                        # silently bind to a non-secure one
> -                        raise
> -                else:
> +                if why[0] != errno.EADDRINUSE:
>                      raise
> +        raise Exception('failed to find available secure port')
>  
>  
>      def expose(self, address, af, safe=True):
> -- 
> 2.5.0

  reply	other threads:[~2016-01-12 22:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08  7:27 pynfs patch Tigran Mkrtchyan
2015-12-08  7:27 ` [PATCH] Reduce the probability to get port collision when asking for secure port. port collision = same port allocated to 2 different clients trying to connect to the same address Tigran Mkrtchyan
2016-01-12 22:06   ` J. Bruce Fields [this message]
     [not found]     ` <CAOE_DS_M61BJV7UgyBOf7nZStj43xfUbzeSzoS_=gMM6ZDyg=w@mail.gmail.com>
2016-01-13 16:34       ` J. Bruce Fields
2016-01-14  2:00         ` Jeff Layton
2016-01-14 20:00           ` J. Bruce Fields
  -- strict thread matches above, loose matches on Subject: below --
2016-05-19 15:30 [PATCH 1/2] reduce code duplication Tigran Mkrtchyan
2016-05-19 15:30 ` [PATCH] Reduce the probability to get port collision when asking for secure port. port collision = same port allocated to 2 different clients trying to connect to the same address Tigran Mkrtchyan

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=20160112220652.GB8256@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=gil.amsalem@primarydata.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=tigran.mkrtchyan@desy.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.