Clean up bridge device on network create error#51147
Merged
akerouanton merged 1 commit intomoby:masterfrom Oct 13, 2025
Merged
Conversation
When the bridge driver encounters an error during network creation, delete the bridge device if one has been added. Signed-off-by: Rob Murray <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where bridge devices were left behind on the host when bridge network creation failed. The fix ensures proper cleanup by calling deleteNetwork on creation errors and updating the cleanup logic to handle partially constructed networks.
- Modified the
createNetworkmethod to calldeleteNetworkfor cleanup on any error instead of just removing the network reference - Updated
deleteNetworkto safely handle partially constructed networks with null checks - Added integration test to verify bridge devices are properly removed when network creation fails
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| integration/network/bridge/netinit_linux_test.go | Adds integration test to verify bridge cleanup on network creation failure |
| daemon/libnetwork/drivers/bridge/bridge_linux.go | Updates error handling in createNetwork and adds null checks in deleteNetwork |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
corhere
approved these changes
Oct 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
- What I did
Created a bridge network with IPv6 enabled, using nftables, with IPv6 forwarding not enabled on the host. When using nftables, the daemon doesn't enable IP forwarding on the host - it bails out with an error message. But, it's created the bridge device by then, and the bridge device gets left behind on the host.
Any error during bridge network creation, after the bridge device has been added, would have the same effect. (And the bridge is created before any other config happens.)
- How I did it
When the bridge driver encounters an error during network creation, call
deleteNetworkto undo any setup that's happened so far (instead of just dropping the bridge driver's reference to the network).Fixed up
deleteNetworkto cope with a partially constructed network.- How to verify it
New integration test.
- Human readable description for the release notes
- Ensure bridge devices are removed when bridge network creation fails.