Bug 56687 - ProxySourceAddress failed to bind socket to local address
Summary: ProxySourceAddress failed to bind socket to local address
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_proxy_connect (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2014-07-01 09:38 UTC by Arne de Bruijn
Modified: 2015-10-25 05:45 UTC (History)
1 user (show)



Attachments
patch: copy source_address in ap_proxy_connect_to_backend (865 bytes, patch)
2014-07-01 09:38 UTC, Arne de Bruijn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arne de Bruijn 2014-07-01 09:38:01 UTC
Created attachment 31775 [details]
patch: copy source_address in ap_proxy_connect_to_backend

When I use ProxySourceAddress together with mod_proxy_connect to proxy https connections I get occasional error messages in error_log like:

[proxy:error] [pid 8703:tid 139730268100352] (98)Address already in use: [client 192.168.1.192:50519] AH00938: CONNECT: failed to bind socket to local address

and the ProxySourceAddress for that request is ignored.

The cause seems to be that ap_proxy_connect_to_backend (called by mod_proxy_connect) calls apr_socket_bind with conf->source_address directly passed as argument, so the selected local port is stored in conf->source_address and used in subsequent binds. This fails if that port is still in use.

The function ap_proxy_connect_backend (used by mod_proxy_http) makes a copy of conf->source_address before passing it to apr_socket_bind, and when I tried that for ap_proxy_connect_to_backend the problem disappeared (see patch).
Comment 1 frantisek.repkovsky 2015-02-18 14:40:39 UTC
We experience the same issue with Apache 2.4.10. When this will be fixed in Apache 2.4, please?
Comment 2 Robert Augusteijn 2015-06-26 14:26:42 UTC
As a workaround for this bug, you can add the following to your Apache config:

MaxRequestsPerChild 1

This will create a new process for each request, with a fresh conf->source_address. 

Of course this will hurt performance!
Comment 3 frantisek.repkovsky 2015-08-14 07:28:20 UTC
I have used Arne's patch posted previously with the bug report and it seems to be working fine. thanks Arne!

Thanks Robert for workaround too.

I hope, once this bug will be solved officially in some next release of Apache...
Comment 4 Yann Ylavic 2015-09-18 16:44:21 UTC
Thanks, committed in r1703902.
Comment 5 Yann Ylavic 2015-09-18 16:58:13 UTC
Backport proposed to 2.4.x in r1703903.
Comment 6 Christophe JAILLET 2015-10-25 05:45:10 UTC
This is part of 2.4.17