-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add background option to dhcpcd #58526
Conversation
If dhcpcd forks immediately and systemd thinks the network is ready, isn't it possibile that programs needing to bind to an address may randomly fail if the interface is not up yet? |
I am not really an expert, but ArchLinux starts dhcpcd with the -b flag by default: Here is the ArchLinux dhcpcd.service file. Additionally, I kept the standard behaviour - I only added the option of forking to the background, which actually might be helpful in many cases. |
There is a relevant discussion at #50930 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done some testing and I can't find any issue with it. Also all nixos networking and related tests pass.
dhcpcd actually has various other possible configurations regarding waiting:
So perhaps we should have a multiway option e.g.
See also #44524 (comment)
|
See also #35567 (comment) |
FTR, been using this for a while. There may be other issues around this but startups are much better on certain machines. |
Yeah, can we marge this please? |
There has been no response to my feedback above. I suggest not adding half-baked options since it causes user friction if they are removed later :) Note also that the unit ordering issue has been fixed, so you shouldn't be experiencing delayed starts anyway unless you're still on 19.03, in which case you could employ any of various workarounds. |
ping @bene1618 |
I tried to implement @gloaming 's suggestion. I do not really understand if the standard behaviour (without any of the options) differs from "waitip", so I left out the "if-network-up" option. |
As I understand it, the default behaviour is equivalent to Now that we have
|
IPv6 = "waitip 6"; | ||
both = "waitip 4\nwaitip 6"; | ||
default = ""; | ||
}.${cfg.wait}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default
here doesn't achieve anything. If you wanted a default you'd have to use { ... }.${cfg.wait} or ""
. But I don't think there's any reasonable default here anyways, so it should be okay to just not have one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems I was a bit tired. The dhcpcd default behaviour is selected with the option "if-carrier-up". And due to @gloaming's comment, this behaviour should differ from the other options available. The relevant part in the dhcpcd man page is:
If any interface reports a working carrier then dhcpcd will try and obtain a lease before forking to the background, otherwise it will fork right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'm not a fan of effectively disabling network-online.target
, exposing this configuration option explicitly does make sense to me instead of hardcoding it into the commandline. Thanks!
Updates? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me once the commits are squashed
I seem to have closed the pull request accidentally by doing something wrong with the push of the squashed commit. Now I don't see how I can reopen it again. Github claims that there are no new commits on the bene1618:master branch, but there is one: bene1618@0767de3 Could someone maybe help me what I have to do now? |
Not sure, but you can also just open a new PR. Generally I also suggest creating a new branch for every PR |
Yep 👍 @bene1618 You really shouldn't use the
and PR. |
Yes, I also realized that shortly after I had opened this pull request. I have now opened a new one at #78745. |
Motivation for this change
DHCP waits for an IP address to be assigned before forking to background. This causes a lag during startup. I removed the -w option from the .service file, and added it, optionally, to the dhcpcd.config file. One can now make dhcpcd fork to background automatically by adding "networking.dhcpcd.background = true;" in the NixOS configuration. On my system, this reduced userspace startup time from about 11s to about 3s.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)