@@ -621,7 +621,17 @@ class TCanceler
621
621
void SetFuture (TFuture<void > awaitable)
622
622
{
623
623
auto guard = Guard (Lock_);
624
- Future_ = std::move (awaitable);
624
+ if (!IsCanceled ()) {
625
+ Future_ = std::move (awaitable);
626
+ return ;
627
+ }
628
+
629
+ guard.Release ();
630
+
631
+ ErrorSet_.Wait ();
632
+
633
+ YT_ASSERT (!CancelationError_.IsOK ());
634
+ awaitable.Cancel (CancelationError_);
625
635
}
626
636
627
637
void ResetFuture ()
@@ -644,6 +654,8 @@ class TCanceler
644
654
future = std::move (Future_);
645
655
}
646
656
657
+ ErrorSet_.NotifyAll ();
658
+
647
659
if (future) {
648
660
YT_LOG_DEBUG (" Sending cancelation to fiber, propagating to the awaited future (TargetFiberId: %x)" ,
649
661
FiberId_);
@@ -654,12 +666,6 @@ class TCanceler
654
666
}
655
667
}
656
668
657
- TError GetCancelationError () const
658
- {
659
- auto guard = Guard (Lock_);
660
- return CancelationError_;
661
- }
662
-
663
669
void Run (const TError& error)
664
670
{
665
671
Cancel (error);
@@ -680,6 +686,7 @@ class TCanceler
680
686
const TFiberId FiberId_;
681
687
682
688
std::atomic<bool > Canceled_ = false ;
689
+ NThreading::TEvent ErrorSet_;
683
690
NThreading::TSpinLock Lock_;
684
691
TError CancelationError_;
685
692
TFuture<void > Future_;
@@ -1173,10 +1180,6 @@ void WaitUntilSet(TFuture<void> future, IInvokerPtr invoker)
1173
1180
GetCurrentFiberCanceler ();
1174
1181
1175
1182
const auto & canceler = NDetail::GetFiberSwitchHandler ()->Canceler ();
1176
- if (canceler->IsCanceled ()) {
1177
- future.Cancel (canceler->GetCancelationError ());
1178
- }
1179
-
1180
1183
canceler->SetFuture (future);
1181
1184
auto finally = Finally ([&] {
1182
1185
canceler->ResetFuture ();
0 commit comments