Calling TextService:GetTextBoundsAsync multiple times leads to requests never completing (thread leaks)

Reproduction Steps

Calling TextService:GetTextBoundsAsync(params) multiple times in a row stops the previous requests from completing. This is problematic because you cannot query for different types of text in a row. For example, if I’m trying to size 2 labels manually, then I would need to make 2 calls at the same time. I expect both to complete.

The following code reproduces this bug:

local TextService = game:GetService("TextService")

for i=1, 5 do
	task.spawn(function()
		local params = Instance.new("GetTextBoundsParams")
		params.Text = "Doors"
		params.Size = 64
		params.Font = Font.new("rbxasset://fonts/families/JosefinSans.json", Enum.FontWeight.Light, Enum.FontStyle.Italic)
		params.Width = 10*64
		
		print("query", i)
		local result = TextService:GetTextBoundsAsync(params)
		print("done with query", result, i)
	end)
end

The following output is what you get

  query 1
  query 2
  query 3
  query 4
  query 5
  done with query 162, 64 5

I expect the following

  query 1
  query 2
  query 3
  query 4
  query 5
  done with query 162, 64 1
  done with query 162, 64 2
  done with query 162, 64 3
  done with query 162, 64 4
  done with query 162, 64 5

Basically, we drop the 4 previous queries somehow.

This only reproduces on a font not already downloaded to Roblox.

Expected Behavior

I expect size queries to always return after querying.

Actual Behavior

All but the last query is cancelled. This is very sad, and kind of annoying.

Workaround

I’m going to end up with some promise queue as a work-around, but this is not great for performance.

Issue Area: Engine
Issue Type: Other
Impact: Moderate
Frequency: Constantly
Date First Experienced: 2022-12-19 00:12:00 (-08:00)

14 Likes

Thanks for the report! We’ll take a look.

2 Likes

Would like to bump this topic, I can still reproduce this bug and it happens especially frequently in studio for me.

I’m taking a look at this right now! Hoping to get a patch out, but our release cycle is slowish right now, so no promises on exact timing! Just wanted to let everyone know this is being looked at.

Update: I found a fix, it’s going through code review and release cycle now!
Update 2 (4/13/2023): Fix is in main, and now we’re waiting for release and flag flip. Please wait a few weeks!

5 Likes

This is released now! (Has been for a while), and everything looks stable!

4 Likes