NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.3k stars 13.54k forks source link

nondeterministic behaviour of nixos containers #54389

Open nek0 opened 5 years ago

nek0 commented 5 years ago

Issue description

when using multiple nixos-containers with private networks and forwarded ports from host to container on the same host, the ports are not forwarded deterministically to the container, as they start simultaneously and cause some kind of race condition in iptables. I've put together a small example as nixops configuration file which can easily be run on any 18.09-stable nixos host.

Steps to reproduce

Technical details

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
nek0 commented 3 years ago

I would like to point out, that this issue still persists. when mutliple containers get started at the same time, iptables fails to create all port forwardings neccessary.

Mic92 commented 3 years ago

We currently start systemd-nspawn directly for declarative containers. Systemd-nspawn talks with the kernel directly to issue iptables rules. I think there is a race condition when multiple systemd-nspawn container are run in parallel. One solution might be to use systemd-machined or create all containers in serial instead parallel.

Mic92 commented 3 years ago

Also see https://github.com/systemd/systemd/blob/edf370af9e9fafad01393699e7a6f34bf0568dd6/src/nspawn/nspawn-expose-ports.c#L100

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

Mic92 commented 3 years ago

I don't this have been solved.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

nek0 commented 1 year ago

Has this been solved yet?