Skip to content

Clean up bridge device on network create error#51147

Merged
akerouanton merged 1 commit intomoby:masterfrom
robmry:create_network_error_handling
Oct 13, 2025
Merged

Clean up bridge device on network create error#51147
akerouanton merged 1 commit intomoby:masterfrom
robmry:create_network_error_handling

Conversation

@robmry
Copy link
Contributor

@robmry robmry commented Oct 9, 2025

- 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 deleteNetwork to undo any setup that's happened so far (instead of just dropping the bridge driver's reference to the network).

Fixed up deleteNetwork to 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.

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]>
@robmry robmry self-assigned this Oct 9, 2025
@robmry robmry added this to the 29.0.0 milestone Oct 9, 2025
@robmry robmry requested a review from Copilot October 9, 2025 16:55
@robmry robmry marked this pull request as ready for review October 9, 2025 16:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 createNetwork method to call deleteNetwork for cleanup on any error instead of just removing the network reference
  • Updated deleteNetwork to 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.

@robmry robmry requested review from akerouanton and corhere October 9, 2025 17:17
Copy link
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.

LGTM

Copy link
Member

@akerouanton akerouanton left a comment

Choose a reason for hiding this comment

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

LGTM

@akerouanton akerouanton merged commit 06a78dc into moby:master Oct 13, 2025
189 of 193 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants