Modules never resolve if the root thread ever yields

Reproduction Steps
Script

require(module)
print('resumed')

Module

local thread = coroutine.running()
task.defer(coroutine.resume, thread)
coroutine.yield()
print('finished')
return 1

Expected Behavior
output finished and then resumed

The Script thread should resume, resolving the require as 1 after once Module finishes running

Actual Behavior
output only finished not resumed

The Script thread does not resume after Module finishes

Issue Area: Engine
Issue Type: Other
Impact: High
Frequency: Constantly

Note: This appears to only happen if you work with the coroutine directly. BindableEvents, for example, can yield and resume without issue.

3 Likes

Yes, this issue occurs as well if you do the same for callbacks like RemoteFunctions, BindableFunction, between other things I probably don’t know.

task.spawn should be used for resuming coroutines now. They gotta fix the issue with coroutine.resume though as well as fixing how Instances behave in weak tables.

By the way here is a very old post of mine, the code is different, but it literally does the same: Glitch with RemoteFunctions? - Help and Feedback / Scripting Support - DevForum | Roblox

1 Like

It does appear that coroutine.resume is the broken component of this interaction

This is probably due to the modulescript code returning while not under the control of the Roblox task scheduler.

Does task.defer(coroutine.running()) work?

Hi, sorry for being late to this. We’ll take a look at this now.

1 Like

As @focasds correctly pointed out you should use task.spawn instead of coroutine.resume. Doing so allows the engine to perform additional work after the thread terminates, such as resuming threads waiting on require, and that’s actually why we added this.