@@ -1051,8 +1051,12 @@ void WallProfiler::SetContext(Isolate* isolate, Local<Value> value) {
1051
1051
if (profData->IsUndefined ()) {
1052
1052
contextPtr = new PersistentContextPtr ();
1053
1053
1054
- auto maybeSetResult =
1055
- cpedObj->Set (v8Ctx, localSymbol, External::New (isolate, contextPtr));
1054
+ auto external = External::New (isolate, contextPtr);
1055
+ setInProgress.store (true , std::memory_order_relaxed);
1056
+ std::atomic_signal_fence (std::memory_order_release);
1057
+ auto maybeSetResult = cpedObj->Set (v8Ctx, localSymbol, external);
1058
+ std::atomic_signal_fence (std::memory_order_release);
1059
+ setInProgress.store (false , std::memory_order_relaxed);
1056
1060
if (maybeSetResult.IsNothing ()) {
1057
1061
delete contextPtr;
1058
1062
return ;
@@ -1076,6 +1080,14 @@ ContextPtr WallProfiler::GetContextPtrSignalSafe(Isolate* isolate) {
1076
1080
return curContext_.Get ();
1077
1081
}
1078
1082
1083
+ auto isSetInProgress = setInProgress.load (std::memory_order_relaxed);
1084
+ std::atomic_signal_fence (std::memory_order_acquire);
1085
+ if (isSetInProgress) {
1086
+ // SetContext is just calling Object::Set on the CPED object, safe behavior
1087
+ // is to not try attempt Object::Get on it and just return empty right now.
1088
+ return std::shared_ptr<Global<Value>>();
1089
+ }
1090
+
1079
1091
auto curGcCount = gcCount.load (std::memory_order_relaxed);
1080
1092
std::atomic_signal_fence (std::memory_order_acquire);
1081
1093
if (curGcCount > 0 ) {
0 commit comments