From 04e93d09455b1fd849ca0706d7b6825a11a45c5c Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Sat, 2 Dec 2017 15:20:25 -0800 Subject: Fix a bug in CreateItem of FunctionLibraryRuntimeImpl. PiperOrigin-RevId: 177710771 --- tensorflow/core/common_runtime/function.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tensorflow/core/common_runtime/function.cc b/tensorflow/core/common_runtime/function.cc index 4c87c922c2..3328125dc9 100644 --- a/tensorflow/core/common_runtime/function.cc +++ b/tensorflow/core/common_runtime/function.cc @@ -552,8 +552,16 @@ Status FunctionLibraryRuntimeImpl::CreateItem(Handle handle, Item** item) { Executor* exec; TF_RETURN_IF_ERROR(NewLocalExecutor(params, g.release(), &exec)); - (*item)->graph = graph; - (*item)->exec = exec; + { + // Guard item since it is already inserted in items_. + mutex_lock l(mu_); + if ((*item)->exec) { + delete exec; + } else { + (*item)->graph = graph; + (*item)->exec = exec; + } + } return Status::OK(); } @@ -572,16 +580,7 @@ Status FunctionLibraryRuntimeImpl::GetOrCreateItem(Handle handle, Item** item) { } // NOTE: We need to call CreateItem out of mu_ because creating an // executor needs to call CreateKernel. - TF_RETURN_IF_ERROR(CreateItem(handle, item)); - - { - mutex_lock l(mu_); - if (items_[local_handle] == nullptr) { - // Insert *item in items_. - items_.insert({local_handle, *item}); - } - } - return Status::OK(); + return CreateItem(handle, item); } void FunctionLibraryRuntimeImpl::RunRemote(const Options& opts, Handle handle, -- cgit v1.2.3