envoy icon indicating copy to clipboard operation
envoy copied to clipboard

Lifecycle bug in WASM filter

Open yanavlasov opened this issue 1 year ago • 0 comments

The shutdownExit envent handler should be held until at least when the registered callback is called:

fyi, this function may has a bug:

void Wasm::initializeLifecycle(Server::ServerLifecycleNotifier& lifecycle_notifier) {
  auto weak = std::weak_ptr<Wasm>(std::static_pointer_cast<Wasm>(shared_from_this()));
  lifecycle_notifier.registerCallback(Server::ServerLifecycleNotifier::Stage::ShutdownExit,
                                      [this, weak](Event::PostCb post_cb) {
                                        auto lock = weak.lock();
                                        if (lock) { // See if we are still alive.
                                          server_shutdown_post_cb_ = std::move(post_cb);
                                        }
                                      });
}

because the comment of registerCallback says the caller should keep the return value(HandlePtr) of registerCallback. Otherwise the callback is unregistered when the return value is deleted.

yanavlasov avatar Aug 28 '24 15:08 yanavlasov