Skip to content

Conversation

@jpsamaroo
Copy link
Member

Hopefully fixes #40626 by not marking or queueing TLS task roots (only current and previous tasks) which are not runnable (and thus may be GC'd if unreferenced elsewhere).

@jpsamaroo jpsamaroo added GC Garbage collector needs tests Unit tests are required for this change labels Oct 31, 2022
@yuyichao
Copy link
Contributor

Intentionally ignoring reachable object is extremely dangerous.

@jpsamaroo
Copy link
Member Author

This is probably wrong to do as-is; I suspect we'll need to also make current_task and previous_task NULL to prevent double-frees.

@jpsamaroo
Copy link
Member Author

@yuyichao my intention is to allow the task's result field to be un-rooted if the containing task has finished and is only held in current_task or previous_task PTLS fields, effectively treating those PTLS fields as weak references. Do you have a recommendation on how to do this safely?

@vtjnash
Copy link
Member

vtjnash commented Nov 1, 2022

We are currently executing code inside this task, so there is no way this can be made to work simply as-is. We need to shallowly visit them here, while skipping the result field. We already have to track (most) tasks for cleaning up their stacks. So if we extend that to covering all tasks, we can perhaps mark/sweep this fields during finalizer and weakref handling?

Additionally, before calling the task_done_hook, we can drop the start and storage fields, since those are not needed anymore.

@vtjnash
Copy link
Member

vtjnash commented Nov 1, 2022

(FWIW, previous_task should almost always be NULL, so I suggest ignoring it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GC Garbage collector needs tests Unit tests are required for this change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread-local current_task keeps garbage alive

3 participants