Skip to content

hot_restart: fix socket handoff for listeners with network namespace addresses - #43653

Merged
ravenblackx merged 4 commits into
envoyproxy:mainfrom
jronak:hot-restart-network-namespace
Mar 2, 2026
Merged

ravenblackx merged 4 commits into
envoyproxy:mainfrom
jronak:hot-restart-network-namespace

Conversation

@jronak

@jronak jronak commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Commit Message: Hot restart socket handoff fails when a listener has network_namespace_filepath configured. The PassListenSocket request only carries the address string (e.g. tcp://0.0.0.0:80), the network namespace is lost. On the parent side, resolveUrl produces an address with networkNamespace() == nullopt, which never matches the listener's namespaced address (since operator== checks namespace equality). The result is fd == -1, the child falls back to binding a new socket, breaking handoff.

This PR fixes it by passing the network namespace hot restart socket handoff path in child and parent handling.

Risk Level: Low, only affects listeners with network_namespace_filepath set, which were already broken during hot restart.

Testing: Updated and added unit tests in hot_restarting_parent_test.cc covering namespace match, mismatch, and mixed (namespace vs no-namespace) cases.
Docs Changes: Updated Changelog
Release Notes: NA
Platform Specific Features: NA

@jronak
jronak force-pushed the hot-restart-network-namespace branch from 3fff32c to 27b1392 Compare February 26, 2026 07:01
Hot restart socket handoff fails when a listener has
network_namespace_filepath configured. The PassListenSocket request only
carries the address string, so the parent resolves an address without a
namespace that never matches the listener's namespaced address.

Thread the network namespace through the PassListenSocket proto, child
request, and parent resolution so that namespaced addresses match
correctly during hot restart.

Signed-off-by: Ronak Jain <[email protected]>
@jronak
jronak force-pushed the hot-restart-network-namespace branch from 27b1392 to b1597be Compare February 26, 2026 07:30
…-namespace

Signed-off-by: Ronak Jain <[email protected]>

Signed-off-by: Ronak Jain <[email protected]>
@jronak
jronak force-pushed the hot-restart-network-namespace branch from 5c5b442 to 82a31ce Compare February 26, 2026 14:49
@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/assign @ravenblackx

@ravenblackx ravenblackx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lots of changes but they're all nitpicky, the general thrust of the PR looks great, thanks!

Comment thread envoy/server/hot_restart.h Resolved
Comment thread source/server/hot_restart_impl.cc Resolved
Comment thread source/server/hot_restart_impl.h Resolved
Comment thread source/server/hot_restarting_parent.cc Resolved
Comment thread test/mocks/server/hot_restart.cc Resolved
Comment thread test/mocks/server/hot_restart.h Resolved
…setup

- Use absl::string_view instead of const std::string& for network_namespace
  parameter across hot restart interfaces
- Use std::make_shared instead of raw new for address construction in tests
- Simplify ON_CALL mock setup to not specify arg matchers
- Use "" instead of std::string() for empty namespace default

Signed-off-by: Ronak Jain <[email protected]>
auto-merge was automatically disabled February 28, 2026 07:46

Head branch was pushed to by a user without write access

Avoids unnecessary local variable by passing the network namespace
directly to the function call.

Signed-off-by: Ronak Jain <[email protected]>
@jronak

jronak commented Feb 28, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@ravenblackx

Copy link
Copy Markdown
Contributor

Normally this would need approval from a senior maintainer too since it touches core code - I'm going to assume @RyanTheOptimist previously enabling auto-merge counts as that endorsement.

@ravenblackx
ravenblackx merged commit 152aa1f into envoyproxy:main Mar 2, 2026
28 of 29 checks passed
bmjask pushed a commit to bmjask/envoy that referenced this pull request Mar 14, 2026
…addresses (envoyproxy#43653)

Commit Message: Hot restart socket handoff fails when a listener has
`network_namespace_filepath` configured. The `PassListenSocket` request
only carries the address string (e.g. `tcp://0.0.0.0:80`), the network
namespace is lost. On the parent side, `resolveUrl` produces an address
with `networkNamespace() == nullopt`, which never matches the listener's
namespaced address (since `operator==` checks namespace equality). The
result is `fd == -1`, the child falls back to binding a new socket,
breaking handoff.

This PR fixes it by passing the network namespace hot restart socket
handoff path in child and parent handling.

Risk Level: Low, only affects listeners with
`network_namespace_filepath` set, which were already broken during hot
restart.

Testing: Updated and added unit tests in `hot_restarting_parent_test.cc`
covering namespace match, mismatch, and mixed (namespace vs
no-namespace) cases.
Docs Changes: Updated Changelog
Release Notes: NA
Platform Specific Features: NA

---------

Signed-off-by: Ronak Jain <[email protected]>
Signed-off-by: bjmask <[email protected]>
bvandewalle pushed a commit to bvandewalle/envoy that referenced this pull request Mar 17, 2026
…addresses (envoyproxy#43653)

Commit Message: Hot restart socket handoff fails when a listener has
`network_namespace_filepath` configured. The `PassListenSocket` request
only carries the address string (e.g. `tcp://0.0.0.0:80`), the network
namespace is lost. On the parent side, `resolveUrl` produces an address
with `networkNamespace() == nullopt`, which never matches the listener's
namespaced address (since `operator==` checks namespace equality). The
result is `fd == -1`, the child falls back to binding a new socket,
breaking handoff.

This PR fixes it by passing the network namespace hot restart socket
handoff path in child and parent handling.

Risk Level: Low, only affects listeners with
`network_namespace_filepath` set, which were already broken during hot
restart.

Testing: Updated and added unit tests in `hot_restarting_parent_test.cc`
covering namespace match, mismatch, and mixed (namespace vs
no-namespace) cases.
Docs Changes: Updated Changelog
Release Notes: NA
Platform Specific Features: NA

---------

Signed-off-by: Ronak Jain <[email protected]>
fishcakez pushed a commit to fishcakez/envoy that referenced this pull request Mar 25, 2026
…addresses (envoyproxy#43653)

Commit Message: Hot restart socket handoff fails when a listener has
`network_namespace_filepath` configured. The `PassListenSocket` request
only carries the address string (e.g. `tcp://0.0.0.0:80`), the network
namespace is lost. On the parent side, `resolveUrl` produces an address
with `networkNamespace() == nullopt`, which never matches the listener's
namespaced address (since `operator==` checks namespace equality). The
result is `fd == -1`, the child falls back to binding a new socket,
breaking handoff.

This PR fixes it by passing the network namespace hot restart socket
handoff path in child and parent handling.

Risk Level: Low, only affects listeners with
`network_namespace_filepath` set, which were already broken during hot
restart.

Testing: Updated and added unit tests in `hot_restarting_parent_test.cc`
covering namespace match, mismatch, and mixed (namespace vs
no-namespace) cases.
Docs Changes: Updated Changelog
Release Notes: NA
Platform Specific Features: NA

---------

Signed-off-by: Ronak Jain <[email protected]>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
…addresses (envoyproxy#43653)

Commit Message: Hot restart socket handoff fails when a listener has
`network_namespace_filepath` configured. The `PassListenSocket` request
only carries the address string (e.g. `tcp://0.0.0.0:80`), the network
namespace is lost. On the parent side, `resolveUrl` produces an address
with `networkNamespace() == nullopt`, which never matches the listener's
namespaced address (since `operator==` checks namespace equality). The
result is `fd == -1`, the child falls back to binding a new socket,
breaking handoff.

This PR fixes it by passing the network namespace hot restart socket
handoff path in child and parent handling.

Risk Level: Low, only affects listeners with
`network_namespace_filepath` set, which were already broken during hot
restart.

Testing: Updated and added unit tests in `hot_restarting_parent_test.cc`
covering namespace match, mismatch, and mixed (namespace vs
no-namespace) cases.
Docs Changes: Updated Changelog
Release Notes: NA
Platform Specific Features: NA

---------

Signed-off-by: Ronak Jain <[email protected]>
mattklein123 pushed a commit that referenced this pull request Sep 30, 2026
…pace (#47492)

### Commit Message
hot restart: inherit listen sockets before entering the network
namespace

### Additional Description
Follow-up to #43653. A listener whose address sets
`network_namespace_filepath` is created by
running the whole socket creation, including the request to the hot
restart parent, inside the
target namespace. If the namespace path can no longer be opened (typical
when a CNI plugin removes
the pod namespace pin after the socket was bound) the namespace switch
fails before the parent is
ever asked, so the successor rejects the listener
(`lds.update_rejected`,
`listener_create_failure`) and the port goes dead once the parent
finishes draining, even though
the parent still holds a valid socket bound in that namespace. An
in-place LDS update of the same
listener masks this, since it clones the socket factory without
reopening the namespace; the loss
only shows up at the next hot restart.

The successor now asks the parent for the socket before entering the
namespace: an inherited
socket is already bound in the right namespace and needs no `setns` to
be duplicated. Entering the
namespace to bind a fresh socket only happens when the parent has none,
so creating a new listener
in a missing namespace still fails cleanly.

### Risk Level
Low. Only affects listeners with `network_namespace_filepath`, and only
reorders the existing
parent-socket request ahead of the namespace switch.

### Testing
New unit tests in `listener_manager_impl_test`: the parent hands over a
socket and the namespace
file is never opened; without a parent socket a missing namespace path
still fails the listener.
Reproduced the loss manually with file-based LDS, a bind-mounted
namespace file, and
`--restart-epoch` 1 then 2 with the namespace removed in between.

### Docs Changes
N/A

### Release Notes
Added a bug-fix changelog fragment.

### Platform Specific Features
Linux only (network namespaces).

---------

Signed-off-by: Bruno Palermo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants