Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

macos: cnid_metad failing to load "setlimits: Invalid argument" #1793

Closed
NJRoadfan opened this issue Nov 29, 2024 · 9 comments · Fixed by #1796
Closed

macos: cnid_metad failing to load "setlimits: Invalid argument" #1793

NJRoadfan opened this issue Nov 29, 2024 · 9 comments · Fixed by #1796
Assignees
Milestone

Comments

@NJRoadfan
Copy link
Contributor

Server OS: macOS 10.15 Catalina

When attempting to launch netatalk, the cnid_metad service fails to launch with message: setlimits: Invalid argument

This is due to setting rlim.rlim_max in a setrlimit() call to 65535 when macOS limits this variable to 10240 (ref: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/syslimits.h and minio/minio#9855)

static int setlimits(void)
{
struct rlimit rlim;
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
LOG(log_error, logtype_afpd, "setlimits: %s", strerror(errno));
exit(1);
}
if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < 65535) {
rlim.rlim_cur = 65535;
if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_max < 65535)
rlim.rlim_max = 65535;
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
LOG(log_error, logtype_afpd, "setlimits: %s", strerror(errno));
exit(1);
}
}
return 0;

Fix: Under macOS, set limit to 10240 instead of 65535. There are ways to change this at the system level, but it likely isn't needed.

@NJRoadfan
Copy link
Contributor Author

Note: afpd has similar setlimits() function in main.c as well, although it doesn't seem to stop the daemon from launching.

@rdmark
Copy link
Member

rdmark commented Nov 30, 2024

Are there any particular preconditions required to trigger this code path on macOS?

I have not observed it on macOS 14 or 15.

Regardless, I agree that lowering the number of permitted opened files to ~10k seems reasonable.

@rdmark rdmark added this to the release-4.0 milestone Nov 30, 2024
@NJRoadfan
Copy link
Contributor Author

Just compile and run. Looking at the Emaculation thread, others have had the problem, so it appears to be OS version dependent.

@rdmark
Copy link
Member

rdmark commented Nov 30, 2024

Can you please share the URL to the Emaculation thread? Sorry if you already did and I couldn’t find it. :)

To encapsulate this change, I suggest we introduce a MACOS (or DARWIN) compatibility macro.

@NJRoadfan
Copy link
Contributor Author

https://www.emaculation.com/forum/viewtopic.php?t=11123

Apple has a macro already, should be defined as __APPLE__ although some sources state that __MACH__ should be used alongside of it.

@rdmark
Copy link
Member

rdmark commented Nov 30, 2024

Do you want to attempt the PR or should I?

@NJRoadfan
Copy link
Contributor Author

I am a bit occupied with other commitments at the moment. In my testing, I just changed rlim.rlim_cur and rlim.rlim_max to 10240 in the above snippet and it worked on Catalina.

@rdmark rdmark linked a pull request Dec 1, 2024 that will close this issue
@rdmark
Copy link
Member

rdmark commented Dec 1, 2024

This seems to have not broken anything on macOS 15.1.1 -- #1796

@rdmark
Copy link
Member

rdmark commented Dec 2, 2024

Interestingly, macOS 15 reports a slightly higher upper limit:

ulimit -u
10666

Edit: strike that. -u gets you the process limit. The file descriptor limit switch is -n.

Additionally, by default ulimit gets you the soft limit. -H has to be added for the hard limit.

ulimit -nH    
unlimited
ulimit -nS
2560

https://ss64.com/bash/ulimit.html

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants