@@ -66,9 +66,7 @@ CoreWorker::CoreWorker(const WorkerType worker_type, const Language language,
66
66
const std::string &log_dir, const std::string &node_ip_address,
67
67
int node_manager_port,
68
68
const TaskExecutionCallback &task_execution_callback,
69
- std::function<Status()> check_signals,
70
- const std::function<void ()> exit_handler,
71
- bool ref_counting_enabled)
69
+ std::function<Status()> check_signals, bool ref_counting_enabled)
72
70
: worker_type_(worker_type),
73
71
language_ (language),
74
72
log_dir_(log_dir),
@@ -106,12 +104,13 @@ CoreWorker::CoreWorker(const WorkerType worker_type, const Language language,
106
104
RAY_CHECK (task_execution_callback_ != nullptr );
107
105
auto execute_task = std::bind (&CoreWorker::ExecuteTask, this , std::placeholders::_1,
108
106
std::placeholders::_2, std::placeholders::_3);
107
+ auto exit = std::bind (&CoreWorker::Shutdown, this );
109
108
raylet_task_receiver_ =
110
109
std::unique_ptr<CoreWorkerRayletTaskReceiver>(new CoreWorkerRayletTaskReceiver (
111
- worker_context_.GetWorkerID (), raylet_client_, execute_task, exit_handler ));
110
+ worker_context_.GetWorkerID (), raylet_client_, execute_task, exit ));
112
111
direct_task_receiver_ =
113
112
std::unique_ptr<CoreWorkerDirectTaskReceiver>(new CoreWorkerDirectTaskReceiver (
114
- worker_context_, task_execution_service_, execute_task, exit_handler ));
113
+ worker_context_, task_execution_service_, execute_task, exit ));
115
114
}
116
115
117
116
// Start RPC server after all the task receivers are properly initialized.
@@ -212,26 +211,25 @@ CoreWorker::CoreWorker(const WorkerType worker_type, const Language language,
212
211
}
213
212
214
213
CoreWorker::~CoreWorker () {
215
- Shutdown ();
214
+ io_service_. stop ();
216
215
io_thread_.join ();
216
+ if (log_dir_ != " " ) {
217
+ RayLog::ShutDownRayLog ();
218
+ }
217
219
}
218
220
219
221
void CoreWorker::Shutdown () {
220
- if (!shutdown_) {
221
- shutdown_ = true ;
222
- io_service_.stop ();
223
- if (worker_type_ == WorkerType::WORKER) {
224
- task_execution_service_.stop ();
225
- }
226
- if (log_dir_ != " " ) {
227
- RayLog::ShutDownRayLog ();
228
- }
222
+ io_service_.stop ();
223
+ if (worker_type_ == WorkerType::WORKER) {
224
+ task_execution_service_.stop ();
229
225
}
230
226
}
231
227
232
228
void CoreWorker::Disconnect () {
233
229
io_service_.stop ();
234
- gcs_client_->Disconnect ();
230
+ if (gcs_client_) {
231
+ gcs_client_->Disconnect ();
232
+ }
235
233
if (raylet_client_) {
236
234
RAY_IGNORE_EXPR (raylet_client_->Disconnect ());
237
235
}
0 commit comments