From 2c75dbfd2d37a3c06d34cc4b12682a63a75503f7 Mon Sep 17 00:00:00 2001 From: Jiri Simsa Date: Tue, 29 May 2018 18:10:27 -0700 Subject: [PATCH] Making RPC op handle the case where cancellation manager is not initialized in OpKernelContext. Fixes #19496 PiperOrigin-RevId: 198488860 --- tensorflow/core/util/rpc/call_container.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tensorflow/core/util/rpc/call_container.h b/tensorflow/core/util/rpc/call_container.h index e1226a7..39ead10 100644 --- a/tensorflow/core/util/rpc/call_container.h +++ b/tensorflow/core/util/rpc/call_container.h @@ -102,7 +102,9 @@ CallContainer::CallContainer( typename CallContainer::StartCallFn start_call_fn) : ctx_(ctx), done_(std::move(done)), - token_(ctx->cancellation_manager()->get_cancellation_token()), + token_(ctx->cancellation_manager() != nullptr + ? ctx->cancellation_manager()->get_cancellation_token() + : CancellationManager::kInvalidToken), fail_fast_(fail_fast), try_rpc_(try_rpc), callback_destroyed_(new Notification) { @@ -110,7 +112,9 @@ CallContainer::CallContainer( // This will run when all RPCs are finished. reffed_status_callback_ = new ReffedStatusCallback([this](const Status& s) { - ctx_->cancellation_manager()->DeregisterCallback(token_); + if (token_ != CancellationManager::kInvalidToken) { + ctx_->cancellation_manager()->DeregisterCallback(token_); + } ctx_->SetStatus(s); done_(); callback_destroyed_->WaitForNotification(); @@ -125,11 +129,14 @@ CallContainer::CallContainer( std::shared_ptr notify_when_destroyed( new internal::NotifyWhenDestroyed(callback_destroyed_)); std::shared_ptr calls_started(new Notification); - bool is_cancelled = !ctx_->cancellation_manager()->RegisterCallback( - token_, [this, calls_started, notify_when_destroyed]() { - calls_started->WaitForNotification(); - StartCancel(); - }); + bool is_cancelled = false; + if (token_ != CancellationManager::kInvalidToken) { + is_cancelled = !ctx_->cancellation_manager()->RegisterCallback( + token_, [this, calls_started, notify_when_destroyed]() { + calls_started->WaitForNotification(); + StartCancel(); + }); + } for (int i = 0; i < num_calls; ++i) { create_call_fn(this, i); -- 2.7.4