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.
This commit is contained in:
Garen Chan
2021-08-25 03:54:21 +08:00
committed by GitHub
parent 641780a9c6
commit 945a83d406

View File

@@ -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;
}