From 945a83d40661981f5098de0d89d8cbcd88883f15 Mon Sep 17 00:00:00 2001 From: Garen Chan <1412950785@qq.com> Date: Wed, 25 Aug 2021 03:54:21 +0800 Subject: [PATCH] Fix boundary problem of adjusting open files limit. (#5722) When `decr_step` is greater than `oldlimit`, the final `bestlimit` may be invalid. For example, oldlimit = 10, decr_step = 16. Current bestlimit = 15 and setrlimit() failed. Since bestlimit is less than decr_step , then exit the loop. The final bestlimit is larger than oldlimit but is invalid. Note that this only matters if the system fd limit is below 16, so unlikely to have any actual effect. --- src/server.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 666b7cdcec..d0fa5d0f09 100644 --- a/src/server.c +++ b/src/server.c @@ -2942,7 +2942,10 @@ void adjustOpenFilesLimit(void) { /* We failed to set file limit to 'bestlimit'. Try with a * smaller limit decrementing by a few FDs per iteration. */ - if (bestlimit < decr_step) break; + if (bestlimit < decr_step) { + bestlimit = oldlimit; + break; + } bestlimit -= decr_step; }