Repository: envoyproxy/envoy
File: source/server/hot_restarting_child.cc (C++)

Code before:
      udp_forwarding_context_.getListenerForDestination(*data.addresses_.local_);
  if (addr_and_listener.has_value()) {
    auto [addr, listener_config] = *addr_and_listener;
    // We send to the worker index from the parent instance.
    // In the case that the number of workers changes between instances,
    // or the quic connection id generator changes how it selects worker
    // ids, the hot restart packet transfer will fail.
    //
    // One option would be to dispatch an onData call to have the receiving
    // worker forward the packet if the calculated destination differs from
    // the parent instance worker index; however, this would require
    // temporarily disabling kernel_worker_routing_ in each instance of
    // ActiveQuicListener, and a much more convoluted pipeline to collect
    // the set of destinations (listenerWorkerRouter doesn't currently
    // expose the actual listeners.)
    //
    // Since the vast majority of hot restarts will change neither of these
    // things, this implementation is "pretty good", and much better than no
    // hot restart capability at all.
    listener_config->listenerWorkerRouter(*addr).deliver(worker_index, std::move(data));
  }
}

int HotRestartingChild::duplicateParentListenSocket(const std::string& address,
                                                    uint32_t worker_index,
                                                    const std::string& network_namespace) {
  if (parent_terminated_) {
    return -1;
  }

  HotRestartMessage wrapped_request;
  wrapped_request.mutable_request()->mutable_pass_listen_socket()->set_address(address);
  wrapped_request.mutable_request()->mutable_pass_listen_socket()->set_worker_index(worker_index);
  wrapped_request.mutable_request()->mutable_pass_listen_socket()->set_network_namespace(
      network_namespace);
  main_rpc_stream_.sendHotRestartMessage(parent_address_, wrapped_request);

  std::unique_ptr<HotRestartMessage> wrapped_reply =
      main_rpc_stream_.receiveHotRestartMessage(RpcStream::Blocking::Yes);
  if (!main_rpc_stream_.replyIsExpectedType(wrapped_reply.get(),
                                            HotRestartMessage::Reply::kPassListenSocket)) {
    return -1;
  }
  return wrapped_reply->reply().pass_listen_socket().fd();
}

std::unique_ptr<HotRestartMessage> HotRestartingChild::getParentStats() {
  if (parent_terminated_ || skip_parent_stats_) {
    return nullptr;
  }


Review comment (suggestion):
```suggestion
                                                    absl::string_view network_namespace) {
```

Code after:
      udp_forwarding_context_.getListenerForDestination(*data.addresses_.local_);
  if (addr_and_listener.has_value()) {
    auto [addr, listener_config] = *addr_and_listener;
    // We send to the worker index from the parent instance.
    // In the case that the number of workers changes between instances,
    // or the quic connection id generator changes how it selects worker
    // ids, the hot restart packet transfer will fail.
    //
    // One option would be to dispatch an onData call to have the receiving
    // worker forward the packet if the calculated destination differs from
    // the parent instance worker index; however, this would require
    // temporarily disabling kernel_worker_routing_ in each instance of
    // ActiveQuicListener, and a much more convoluted pipeline to collect
    // the set of destinations (listenerWorkerRouter doesn't currently
    // expose the actual listeners.)
    //
    // Since the vast majority of hot restarts will change neither of these
    // things, this implementation is "pretty good", and much better than no
    // hot restart capability at all.
    listener_config->listenerWorkerRouter(*addr).deliver(worker_index, std::move(data));
  }
}

int HotRestartingChild::duplicateParentListenSocket(const std::string& address,
                                                    uint32_t worker_index,
                                                    absl::string_view network_namespace) {
  if (parent_terminated_) {
    return -1;
  }

  HotRestartMessage wrapped_request;
  wrapped_request.mutable_request()->mutable_pass_listen_socket()->set_address(address);
  wrapped_request.mutable_request()->mutable_pass_listen_socket()->set_worker_index(worker_index);
  wrapped_request.mutable_request()->mutable_pass_listen_socket()->set_network_namespace(
      network_namespace);
  main_rpc_stream_.sendHotRestartMessage(parent_address_, wrapped_request);

  std::unique_ptr<HotRestartMessage> wrapped_reply =
      main_rpc_stream_.receiveHotRestartMessage(RpcStream::Blocking::Yes);
  if (!main_rpc_stream_.replyIsExpectedType(wrapped_reply.get(),
                                            HotRestartMessage::Reply::kPassListenSocket)) {
    return -1;
  }
  return wrapped_reply->reply().pass_listen_socket().fd();
}

std::unique_ptr<HotRestartMessage> HotRestartingChild::getParentStats() {
  if (parent_terminated_ || skip_parent_stats_) {
    return nullptr;
  }