# \[CRITICAL\] Defer does not execute after cancellation through race

**URL:** <https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174>\
**Category:** Issues and Bug Reporting\
**Tags:** open, unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [October 20, 2024, 2:01pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174 "2024-10-20T14:01:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 20, 2024, 2:01pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/1 "2024-10-20T14:01:58Z")

</div>

### Summary

Here’s the repro

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

test_device := class(creative_device):

    StartFail()<suspends>:void=
        Print("StartFail")
        defer:
            Print("StartFail Ended (from suspending scope)") # Never prints
        
        race:
            Sleep(Inf)
            Sleep(Inf)

        Sleep(Inf)

    StartSucceed()<suspends>:void=
        Print("StartSucceed")
        defer:
            Print("StartSucceed Ended (from suspending scope)") # Prints correctly
        
        # race:
        # Sleep(Inf)
        # Sleep(Inf)

        Sleep(Inf)

    OnBegin<override>()<suspends>:void=
        race:
            Sleep(1.0)
            StartFail()
            StartSucceed() # Not required to repro

```

Prints

```auto
[2024.10.20-13.59.20:863][673]LogVerse: : StartFail
[2024.10.20-13.59.20:864][673]LogVerse: : StartSucceed
[2024.10.20-13.59.21:854][790]LogVerse: : StartSucceed Ended (from suspending scope)

```

(As you can see the StartFail defer never fires, this is an issue when trying to build complex async structures)

### Please select what you are reporting on:

Verse

### What Type of Bug are you experiencing?

Verse

### Steps to Reproduce

See summary

### Expected Result

See summary

### Observed Result

See summary

### Platform(s)

PC

---

<div class="post-metadata">

**Author:** ![Daigoro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daigoro](https://forums.unrealengine.com/u/Daigoro)\
**Post date:** [October 20, 2024, 2:39pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/3 "2024-10-20T14:39:23Z")

</div>

Can confirm it.

---

<div class="post-metadata">

**Author:** ![Enebz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/enebz/32/875411_2.png) [@Enebz](https://forums.unrealengine.com/u/Enebz)\
**Post date:** [December 6, 2024, 5:31am UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/4 "2024-12-06T05:31:58Z")

</div>

I’d love to see this fixed!

---

<div class="post-metadata">

**Author:** ![Konerds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Konerds](https://forums.unrealengine.com/u/Konerds)\
**Post date:** [June 3, 2025, 11:04pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/5 "2025-06-03T23:04:20Z")

</div>

It’s not fixed yet. I got the same issue. This is critical when using composed pattern with concurrency.

---

<div class="post-metadata">

**Author:** ![Bug-Reporter](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bug-reporter/32/1223650_2.png) [@Bug-Reporter](https://forums.unrealengine.com/u/Bug-Reporter)\
**Post date:** [July 21, 2026, 8:00pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/6 "2026-07-21T20:00:42Z")

</div>

FORT-807923 has been ‘Backlogged’. This is an issue that is in a queue to be addressed.

---

<div class="post-metadata">

**Author:** ![EnebzVerse](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/enebzverse/32/1169872_2.png) [@EnebzVerse](https://forums.unrealengine.com/u/EnebzVerse)\
**Post date:** [September 8, 2026, 8:25pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/7 "2026-09-08T20:25:17Z")

</div>

Me too!

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 8, 2026, 8:26pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/8 "2026-09-08T20:26:14Z")

</div>

Previous Enebz did not know about Verse, tell em

---

<div class="post-metadata">

**Author:** ![EnebzVerse](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/enebzverse/32/1169872_2.png) [@EnebzVerse](https://forums.unrealengine.com/u/EnebzVerse)\
**Post date:** [September 8, 2026, 8:26pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/9 "2026-09-08T20:26:43Z")

</div>

This gets fixed with the new VM. No plans to fix in BPVM.

---

<div class="post-metadata">

**Author:** ![AtAshTag](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/atashtag/32/997253_2.png) [@AtAshTag](https://forums.unrealengine.com/u/AtAshTag)\
**Post date:** [September 8, 2026, 10:53pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/10 "2026-09-08T22:53:00Z")

</div>

Do we have a date for that or not seems very hush hush ?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 8, 2026, 11:04pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/11 "2026-09-08T23:04:15Z")

</div>

You can check [the roadmap](https://dev.epicgames.com/community/fortnite/roadmap)

---

<div class="post-metadata">

**Author:** ![AtAshTag](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/atashtag/32/997253_2.png) [@AtAshTag](https://forums.unrealengine.com/u/AtAshTag)\
**Post date:** [September 8, 2026, 11:07pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/12 "2026-09-08T23:07:57Z")

</div>

Doesn’t say a date. that said Q1 initially so i aint believing anything unless i see it or its confirmed.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 9, 2026, 12:26am UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/13 "2026-09-09T00:26:50Z")

</div>

It says Q3 Confidence: High, it should be coming soon at this point

---

<div class="post-metadata">

**Author:** ![Sprintermax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sprintermax/32/1037175_2.png) [@Sprintermax](https://forums.unrealengine.com/u/Sprintermax)\
**Post date:** [September 10, 2026, 3:29pm UTC](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174/14 "2026-09-10T15:29:56Z")

</div>

Due to that behavior difference, we can do this xD

```verse
# Besides being suspends, it returns instantly on the same tick (has syncronous behavior):
IsVerseVM<public>()<suspends>:logic =
    var Result : logic = false
    race:
        block:
            defer. set Result = true
            race { Sleep(Inf); Sleep(Inf) }
        Sleep(-1.0)
    return Result

```

If you prefer, there is also this approach, which does the exact same. It just does not have the suspends effect

```verse
vvm_test_class<internal> := class<allocates>:
    var<private> Result<internal> : logic -= false

    CheckForVerseVM<internal>()<suspends>:void = race:
        block:
            defer. set Self.Result = true
            race { Sleep(Inf); Sleep(Inf) }
        Sleep(-1.0)

IsVerseVM<public>():logic =
    TestClass := vvm_test_class{}
    spawn. TestClass.CheckForVerseVM()
    return TestClass.Result

```
