-
Notifications
You must be signed in to change notification settings - Fork 5.5k
server: wait workers to start before draining parent. #14319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
0f79a67
3f09b9d
7627986
e6e3c90
f84c3f8
871c415
1143ecc
50c3946
9c942c2
c93ab4f
c6b8a32
afc4d8b
46f9047
22f482f
bad5177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -606,15 +606,22 @@ void InstanceImpl::onRuntimeReady() { | |
| } | ||
|
|
||
| void InstanceImpl::startWorkers() { | ||
| listener_manager_->startWorkers(*worker_guard_dog_); | ||
| initialization_timer_->complete(); | ||
| // Update server stats as soon as initialization is done. | ||
| updateServerStats(); | ||
| workers_started_ = true; | ||
| // At this point we are ready to take traffic and all listening ports are up. Notify our parent | ||
| // if applicable that they can stop listening and drain. | ||
| restarter_.drainParentListeners(); | ||
| drain_manager_->startParentShutdownSequence(); | ||
| // The callback will be called after workers are started. | ||
| listener_manager_->startWorkers(*worker_guard_dog_, [this]() { | ||
| if (isShutdown()) { | ||
| return; | ||
| } | ||
|
Comment on lines
+614
to
+616
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have test coverage of this case? (Put an ASSERT in there and see if it's hit or look at coverage report)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test for this in the new commit. |
||
|
|
||
| initialization_timer_->complete(); | ||
| // Update server stats as soon as initialization is done. | ||
| updateServerStats(); | ||
| workers_started_ = true; | ||
| notifyCallbacksForStage(Stage::WorkerStarted); | ||
| // At this point we are ready to take traffic and all listening ports are up. Notify our | ||
| // parent if applicable that they can stop listening and drain. | ||
| restarter_.drainParentListeners(); | ||
| drain_manager_->startParentShutdownSequence(); | ||
| }); | ||
| } | ||
|
|
||
| Runtime::LoaderPtr InstanceUtil::createRuntime(Instance& server, | ||
|
|
@@ -710,6 +717,11 @@ void InstanceImpl::run() { | |
| // startup (see RunHelperTest in server_test.cc). | ||
| const auto run_helper = RunHelper(*this, options_, *dispatcher_, clusterManager(), | ||
| access_log_manager_, init_manager_, overloadManager(), [this] { | ||
| if (!startup_) { | ||
| notifyCallbacksForStage(Stage::Startup); | ||
| startup_ = true; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain these changes? It's not clear to my why they were made. Please add more comments both here and below if they are necessary.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures Startup notifications to be sent first. Otherwise at LifecycleNotifications test , the notification order will be |
||
|
|
||
| notifyCallbacksForStage(Stage::PostInit); | ||
| startWorkers(); | ||
| }); | ||
|
|
@@ -718,7 +730,12 @@ void InstanceImpl::run() { | |
| ENVOY_LOG(info, "starting main dispatch loop"); | ||
| auto watchdog = main_thread_guard_dog_->createWatchDog(api_->threadFactory().currentThreadId(), | ||
| "main_thread", *dispatcher_); | ||
| dispatcher_->post([this] { notifyCallbacksForStage(Stage::Startup); }); | ||
| dispatcher_->post([this] { | ||
| if (!startup_) { | ||
| notifyCallbacksForStage(Stage::Startup); | ||
| startup_ = true; | ||
| } | ||
| }); | ||
| dispatcher_->run(Event::Dispatcher::RunType::Block); | ||
| ENVOY_LOG(info, "main dispatch loop exited"); | ||
| main_thread_guard_dog_->stopWatching(watchdog); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,6 +373,9 @@ class InstanceImpl final : Logger::Loggable<Logger::Id::main>, | |
| LifecycleCallbackHandle(std::list<T>& callbacks, T& callback) | ||
| : RaiiListElement<T>(callbacks, callback) {} | ||
| }; | ||
|
|
||
| // startup_ is true means Startup notifications have been called. | ||
| bool startup_{}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this up into the variables section. Also |
||
| }; | ||
|
|
||
| // Local implementation of Stats::MetricSnapshot used to flush metrics to sinks. We could | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used? If this is needed
WorkersStartedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. My preference would be to not make prod changes like this just for tests. If you need synchronization hooks can you use https://github.com/envoyproxy/envoy/blob/master/source/server/listener_hooks.h instead? Thank you.
/wait