Skip to content

Further fix for CowArray to prevent using the refcount from GC #10788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025

Conversation

schveiguy
Copy link
Member

While in a GC finalizer:

  1. This can be run from another thread, the refcount is NOT shared. So decrementing is not safe
  2. The referenced array might already be collected

See #10785 for the first fix, which did some of this, but not for the refcount.

technically, we really should just ban use of the array from inside a finalizer. But this should be enough to get past the segfaults we are seeing.

This does mean that any CowArray!GcPolicy which has a reference from a finalized block, will have extra references that never go away. This is OK, because, if you write to the array, you will make a copy. And then there is now a refcount of 1 again, and the original can truly become garbage. If you read from it, nothing is different.

In general, we should probably examine why we need the complication of this scheme here. Obviously, it has not been fully understood in the context of how the GC works, and It's an internal type, which is only used in std.uni...

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @schveiguy!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + phobos#10788"

@rikkimax
Copy link
Contributor

All that RCness appears to be that it can go away.

Along with this alias: https://github.com/dlang/phobos/blob/e3e5d35d9b9ed5ef596e2396037631a72be4e6ba/std/uni/package.d#L1913C7-L1913C18

Nothing can trigger it.

@kinke kinke merged commit 969a072 into dlang:stable May 22, 2025
9 of 10 checks passed
kinke pushed a commit to symmetryinvestments/phobos that referenced this pull request May 22, 2025
@schveiguy schveiguy deleted the uni-gc-cowarray-segfault2 branch May 22, 2025 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants