Welcome! Log In Create A New Profile

Advanced

Re: [patch] Set SO_REUSEADDR on outgoing TCP connections

Marek Majkowski
April 10, 2014 12:06PM
On Thu, Apr 10, 2014 at 4:40 PM, Maxim Dounin <mdounin@mdounin.ru> wrote:
>> ...
>> The patch will work perfectly well assuming there aren't too many
>> connections to one destination address and port. If that happens the
>> kernel may randomly allocate an outgoing port number that is already
>> used for a given destination and attempt to connect() will fail with
>> EADDRNOTAVAIL. This is fairly easy to detect, and we can just retry
>> connecting again, using another random source port allocated by the
>> kernel.
>
> While it may be interesting approach to overcome the limitation, I
> don't think that this is something that should be done by clients
> in real life. I think it's something kernel should care about,
> not clients.
>
> From practical point of view, trivial solutions are to avoid
> bind() or use multiple addresses for bind().

May I ask how can you specify multiple outgoing IP addresses for a single proxy?

Indeed, this patch does add complexity to the ngx_event_connect_peer
function. Unfortunately nginx currently supports bind before connect
and in current form it severely reduces the number of possible
outgoing connections. Using proxy_bind in current form is harmful.
This patch fixes that.

In perfect world kernel would be able to reuse ports established with
bind before connect. Actually kernel can do that already - this is
what the SO_REUSADDR flag is for. Unfortunately, due to BSD API
compatibility kernel needs to allocate outgoing port on bind() -
before it is told of the destination address. This inevitably may lead
to conflicts indicated by EADDRNOTAVAIL error on connect(), and
results in complexity in proper implementation of bind before connect.

A reasonable solution to bind before connect limitations is to either
merge this patch or retire proxy_bind option.

Cheers,
Marek

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[patch] Set SO_REUSEADDR on outgoing TCP connections Attachments

Marek Majkowski 2314 April 09, 2014 11:54AM

Re: [patch] Set SO_REUSEADDR on outgoing TCP connections

Marek Majkowski 619 April 09, 2014 12:04PM

Re: [patch] Set SO_REUSEADDR on outgoing TCP connections

Maxim Dounin 529 April 10, 2014 11:42AM

Re: [patch] Set SO_REUSEADDR on outgoing TCP connections

Marek Majkowski 725 April 10, 2014 12:06PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 178
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready