Skip to content

Ignore error when adding a bridge already in the ipset#49295

Merged
robmry merged 1 commit intomoby:masterfrom
robmry:ignore_subnet_already_in_ipset
Jan 18, 2025
Merged

Ignore error when adding a bridge already in the ipset#49295
robmry merged 1 commit intomoby:masterfrom
robmry:ignore_subnet_already_in_ipset

Conversation

@robmry
Copy link
Copy Markdown
Contributor

@robmry robmry commented Jan 17, 2025

- What I did

Ignore error "exists" when adding a network to an ipset.

I hit this error somehow, possibly after stopping the daemon in the debugger at an inconvenient point ... then wasn't able to repro.

So, not very satisfactory, but I think this change is the right thing anyway.

- How I did it

- How to verify it

Not sure how to provoke the error naturally. So, to test the errors.Is and the log line, modified the code to deliberately add to the set twice. Got this on startup ...

WARN[2025-01-17T19:26:27.856651959Z] Subnet was already in the ipset bridge=docker0 ipset=docker-ext-bridges-v4 subnet=172.18.0.0/16

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@robmry robmry added area/networking Networking kind/bugfix PR's that fix bugs area/networking/d/bridge Networking labels Jan 17, 2025
@robmry robmry added this to the 28.0.0 milestone Jan 17, 2025
@robmry robmry self-assigned this Jan 17, 2025
@robmry robmry force-pushed the ignore_subnet_already_in_ipset branch from 860754a to feb2dab Compare January 17, 2025 21:54
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM

left some questions, but after seeing it only logs, probably not a blocker

"subnet": maskedAddr,
}).Warnf("Subnet was already in the ipset")
}
n.registerIptCleanFunc(func() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we didn't add it again because it was already there, does that mean we can also skip the "cleanup" function? Could that fail if it's ran multiple times (and therefore failing the second time)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looks like "failing" is in good'Ol libnetwork fashion; fail, log, and continue, so I guess it won't do harm currently, but let me know what you think (also considering the reverse; is it worse if we would skip a cleanup?)

// clean all relevant iptables rules
for _, cleanFunc := range n.iptCleanFuncs {
if errClean := cleanFunc(); errClean != nil {
log.G(context.TODO()).Warnf("Failed to clean iptables rules for bridge network: %v", errClean)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could make the cleanup func also detect a "does not exist" check; does it have such an error defined to check for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's an issue, it was only getting left behind when the daemon stopped. So the cleanup function won't be set up twice. This code isn't called twice for the same subnet.

I can reproduce it now, I must have used the wrong build when I tried before. But it happens when driver init fails, without the fix to make network deletion work in that case. (Perhaps there's some missing cleanup somewhere though, I'll look in to that.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK feel free to merge this one is nothing more is needed in this PR (I kept it open in case you wanted to add changes)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thank you!

@robmry robmry merged commit 0299335 into moby:master Jan 18, 2025
@robmry robmry deleted the ignore_subnet_already_in_ipset branch January 18, 2025 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking/d/bridge Networking area/networking Networking kind/bugfix PR's that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants