Fix select_proxy dead loop in round_roubin_chain

Fix issue #147.
If all proxies are in DOWN_STATE or BUSY_STATE state, select_proxy will run
forever in an infinite loop. When all proxies are not available, we wait some
intervals and retry. The wait time starts with 10 milliseconds and is
increased by 10 milliiseconds in each loop. 14 loops sums up with 1.05 second.
pull/251/head
amyangfei 2018-08-21 16:40:52 +08:00
parent 1c8f8e4e7e
commit 2f8baf1ab5
1 changed files with 10 additions and 1 deletions

View File

@ -569,6 +569,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
unsigned int curr_len = 0;
unsigned int curr_pos = 0;
unsigned int looped = 0; // went back to start of list in RR mode
int rr_loop_max = 14;
p3 = &p4;
@ -615,7 +616,15 @@ int connect_proxy_chain(int sock, ip_type target_ip,
/* We've reached the end of the list, go to the start */
offset = 0;
looped++;
continue;
if (looped > rr_loop_max) {
goto error_more;
} else {
PDEBUG("rr_type all proxies down, release all\n");
release_all(pd, proxy_count);
/* Each loop we wait 10ms more */
usleep(10000 * looped);
continue;
}
} else if (looped && rc > 0 && offset >= curr_pos) {
PDEBUG("GOTO MORE PROXIES 0\n");
/* We've gone back to the start and now past our starting position */