fix test_uasync_socket_race: increase listen() backlog from 32 to 1024
Root cause: accept queue overflow (backlog=32) caused kernel SYN drops. Children waited ~1s for SYN retransmit timeout (5 gaps × 1s = 5s out of 7.2s). With backlog=1024 the timeout drops from ~7.2s to ~0.065s (110× faster).
This commit is contained in:
1 parent
a8ce7d47b7
commit
bfa3e666d4
1 file changed
+5
-6
@@ -117,12 +117,11 @@ int main(void) {
|
||||
#else
|
||||
|
||||
debug_config_init();
|
||||
for (int i = 1; i < DEBUG_CATEGORY_COUNT; i++) debug_set_category_level(i, DEBUG_LEVEL_ERROR);
|
||||
for (int i = 1; i < DEBUG_CATEGORY_COUNT; i++) debug_set_category_level(i, DEBUG_LEVEL_NONE);
|
||||
srand((unsigned)getpid());
|
||||
|
||||
// Резервируем fd 0: dup на высокий fd, close(0), /dev/null на 0.
|
||||
// Гарантирует что accept()/socket() никогда не вернут 0.
|
||||
{ int fd = open("/dev/null", O_RDONLY); if (fd == 0) { /* уже ок */ } else if (fd > 0) { dup2(fd, 0); close(fd); } else { close(0); open("/dev/null", O_RDONLY); } }
|
||||
int fd0 = open("/dev/null", O_RDONLY);
|
||||
if (fd0 == 0) { } else if (fd0 > 0) { dup2(fd0, 0); close(fd0); } else { close(0); open("/dev/null", O_RDONLY); }
|
||||
|
||||
g_port = 25000 + (rand() % 10000);
|
||||
g_ua = uasync_create();
|
||||
@@ -136,7 +135,7 @@ int main(void) {
|
||||
la.sin_family = AF_INET; la.sin_port = htons((uint16_t)g_port);
|
||||
la.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
if (bind(lsock, (struct sockaddr*)&la, sizeof(la)) < 0) { printf("[FAIL] bind: %s\n", strerror(errno)); goto cleanup; }
|
||||
if (listen(lsock, 32) < 0) { printf("[FAIL] listen: %s\n", strerror(errno)); goto cleanup; }
|
||||
if (listen(lsock, 1024) < 0) { printf("[FAIL] listen: %s\n", strerror(errno)); goto cleanup; }
|
||||
uasync_add_socket(g_ua, lsock, on_accept_cb, NULL, NULL, NULL);
|
||||
|
||||
for (int i = 0; i < CHILDREN; i++) {
|
||||
@@ -150,7 +149,7 @@ int main(void) {
|
||||
g_mon_id = uasync_set_timeout(g_ua, 100, NULL, monitor, "mon");
|
||||
void* to_id = uasync_set_timeout(g_ua, TIMEOUT_MS * 10, NULL, test_timeout, "to");
|
||||
|
||||
while (!g_done) uasync_poll(g_ua, 0);
|
||||
while (!g_done) uasync_poll(g_ua, 50);
|
||||
|
||||
if (to_id) uasync_cancel_timeout(g_ua, to_id);
|
||||
|
||||
|
||||
Reference in new issue
Block a user