Skip to content

Commit 275e644

Browse files
amyangfeirofl0r
authored andcommitted
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.
1 parent 1c8f8e4 commit 275e644

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/core.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
569569
unsigned int curr_len = 0;
570570
unsigned int curr_pos = 0;
571571
unsigned int looped = 0; // went back to start of list in RR mode
572+
int rr_loop_max = 14;
572573

573574
p3 = &p4;
574575

@@ -615,13 +616,17 @@ int connect_proxy_chain(int sock, ip_type target_ip,
615616
/* We've reached the end of the list, go to the start */
616617
offset = 0;
617618
looped++;
618-
continue;
619-
} else if (looped && rc > 0 && offset >= curr_pos) {
620-
PDEBUG("GOTO MORE PROXIES 0\n");
621-
/* We've gone back to the start and now past our starting position */
622-
proxychains_proxy_offset = 0;
623-
goto error_more;
624-
}
619+
if (looped > rr_loop_max) {
620+
proxychains_proxy_offset = 0;
621+
goto error_more;
622+
} else {
623+
PDEBUG("rr_type all proxies down, release all\n");
624+
release_all(pd, proxy_count);
625+
/* Each loop we wait 10ms more */
626+
usleep(10000 * looped);
627+
continue;
628+
}
629+
}
625630
PDEBUG("2:rr_offset = %d\n", offset);
626631
rc=start_chain(&ns, p1, RRT);
627632
}

0 commit comments

Comments
 (0)