1 --- a/src/data.c |
|
2 +++ b/src/data.c |
|
3 @@ -337,6 +337,7 @@ static int data_pasv_open(char *reason, off_t size) { |
|
4 static int data_active_open(char *reason, off_t size) { |
|
5 conn_t *c; |
|
6 int bind_port, rev; |
|
7 + int retries = 0; |
|
8 pr_netaddr_t *bind_addr; |
|
9 unsigned char *root_revoke = NULL; |
|
10 |
|
11 @@ -368,7 +369,9 @@ static int data_active_open(char *reason, off_t size) { |
|
12 bind_port = INPORT_ANY; |
|
13 } |
|
14 |
|
15 - session.d = pr_inet_create_conn(session.pool, -1, bind_addr, bind_port, TRUE); |
|
16 + for (;;) { |
|
17 + session.d = pr_inet_create_conn(session.pool, -1, bind_addr, bind_port, |
|
18 + TRUE); |
|
19 |
|
20 /* Default remote address to which to connect for an active transfer, |
|
21 * if the client has not specified a different address via PORT/EPRT, |
|
22 @@ -416,6 +419,15 @@ static int data_active_open(char *reason, off_t size) { |
|
23 |
|
24 if (pr_inet_connect(session.d->pool, session.d, &session.data_addr, |
|
25 session.data_port) == -1) { |
|
26 + |
|
27 + if (session.d->xerrno == EADDRINUSE && retries < 16) { |
|
28 + destroy_pool(session.d->pool); |
|
29 + pr_signals_handle(); |
|
30 + /* Wait up to MSL to avoid TIME_WAIT. */ |
|
31 + sleep(retries++); |
|
32 + continue; |
|
33 + } |
|
34 + |
|
35 pr_log_debug(DEBUG6, |
|
36 "Error connecting to %s#%u for active data transfer: %s", |
|
37 pr_netaddr_get_ipstr(&session.data_addr), session.data_port, |
|
38 @@ -427,6 +439,9 @@ static int data_active_open(char *reason, off_t size) { |
|
39 destroy_pool(session.d->pool); |
|
40 session.d = NULL; |
|
41 return -1; |
|
42 + } else |
|
43 + break; |
|
44 + |
|
45 } |
|
46 |
|
47 c = pr_inet_openrw(session.pool, session.d, NULL, PR_NETIO_STRM_DATA, |
|
48 |
|