diff --git a/changelog.d/+fix-double-bind-zero.fixed.md b/changelog.d/+fix-double-bind-zero.fixed.md new file mode 100644 index 00000000000..8d8b01c24ad --- /dev/null +++ b/changelog.d/+fix-double-bind-zero.fixed.md @@ -0,0 +1 @@ +Fix mirrord making double bind of port 0 fail \ No newline at end of file diff --git a/mirrord/layer/src/socket/ops.rs b/mirrord/layer/src/socket/ops.rs index d1e651cd6ff..e03569b102c 100644 --- a/mirrord/layer/src/socket/ops.rs +++ b/mirrord/layer/src/socket/ops.rs @@ -279,15 +279,17 @@ pub(super) fn bind( // Check if the user's requested address isn't already in use, even though it's not actually // bound, as we bind to a different address, but if we don't check for this then we're // changing normal socket behavior (see issue #1123). - if SOCKETS - .lock()? - .iter() - .any(|(_, socket)| match &socket.state { - SocketState::Initialized | SocketState::Connected(_) => false, - SocketState::Bound(bound) | SocketState::Listening(bound) => { - bound.requested_address == requested_address - } - }) + // We check that port isn't 0 because if it's port 0 it can't really conflict. + if requested_address.port() != 0 + && SOCKETS + .lock()? + .iter() + .any(|(_, socket)| match &socket.state { + SocketState::Initialized | SocketState::Connected(_) => false, + SocketState::Bound(bound) | SocketState::Listening(bound) => { + bound.requested_address == requested_address + } + }) { Err(HookError::AddressAlreadyBound(requested_address))?; }