# Verse: nested coroutine not getting cancelled by a race expression

**URL:** <https://forums.unrealengine.com/t/verse-nested-coroutine-not-getting-cancelled-by-a-race-expression/1375668>\
**Category:** Issues and Bug Reporting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [November 9, 2023, 11:48am UTC](https://forums.unrealengine.com/t/verse-nested-coroutine-not-getting-cancelled-by-a-race-expression/1375668 "2023-11-09T11:48:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt.gosling](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matt.gosling](https://forums.unrealengine.com/u/matt.gosling)\
**Post date:** [November 9, 2023, 11:48am UTC](https://forums.unrealengine.com/t/verse-nested-coroutine-not-getting-cancelled-by-a-race-expression/1375668/1 "2023-11-09T11:48:51Z")

</div>

### Please select what you are reporting on:

Verse

### What Type of Bug are you experiencing?

Verse

### Summary

It is possible to cancel an async function with a race expression, but async functions called by the cancelled function continue running. (Note this is not using spawn{}, it is a nested async function call)

### Steps to Reproduce

Create a new device called test\_device with the following code:

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

test_device := class(creative_device):

    TestEvent : event() = event(){}

    OnBegin<override>()<suspends>:void=
        Sleep(1.0)
        Print("Starting race")
        race:
            TestEvent.Await()
            block:
                Sleep(0.0)
                Func1()
        Print("Finished race")
        
    Func1()<suspends>:void=
        Print("Enter Func1")
        race:
            block:
                TestEvent.Signal()
                Sleep(Inf)
            Func2()

    Func2()<suspends>:void=
        Print("Enter Func2")
        loop:
            Print("Ping")
            Sleep(1.0)

```

### Expected Result

I would expect the following output:  
LogVerse: : Starting race  
LogVerse: : Enter Func1  
LogVerse: : Enter Func2  
LogVerse: : Ping  
LogVerse: : Finished race

### Observed Result

I get the following output:  
LogVerse: : Starting race  
LogVerse: : Enter Func1  
LogVerse: : Finished race  
LogVerse: : Enter Func2  
LogVerse: : Ping  
LogVerse: : Ping  
LogVerse: : Ping  
LogVerse: : Ping  
…

### Platform(s)

Windows PC

### Additional Notes

This may be related to this issue I posted a few days ago regarding defer not working in async functions that self-cancel using Signal/Await:

> [@Verse: defer not always working](https://forums.unrealengine.com/t/verse-defer-not-always-working/1360248):
>
> Please select what you are reporting on: Verse What Type of Bug are you experiencing? Verse Summary Code in ‘defer’ blocks sometimes doesn’t get called. I’m seeing it specifically in async functions that are cancelled by a race block. There are some cases where you can cancel an aync function with a race, and the defer block does get called. In this repro example, the function is in a race with an Await() on an event that the function signals itself, and in this case the defer doesn’t happe…

---

<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:** [May 20, 2024, 7:00pm UTC](https://forums.unrealengine.com/t/verse-nested-coroutine-not-getting-cancelled-by-a-race-expression/1375668/2 "2024-05-20T19:00:08Z")

</div>

The status of FORT-747656 incident has been moved from ‘Unconfirmed’ to ‘Closed’. Resolution Reason: ‘Fixed’

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [May 21, 2024, 5:19pm UTC](https://forums.unrealengine.com/t/verse-nested-coroutine-not-getting-cancelled-by-a-race-expression/1375668/3 "2024-05-21T17:19:24Z")

</div>

Thank you so much for the report, we are working on a fix for a future update.
