Skip to content

race conditions in finalizers #694

@cmcaine

Description

@cmcaine

Hello,

finalizer functions in Julia can interrupt any other code, including other finalizers, which means that any access to shared state must be guarded by some kind of synchronization strategy.

Currently, the finalizers for various GObjects access several bits of shared state without any synchronization and this permits race-conditions, unless there is something quite clever going on that I didn't see.

Here's an unsafe finalizer, delref from gtype.jl (not the only one). Note that it accesses several globals without using atomic operations or locks:

https://github.com/JuliaGraphics/Gtk.jl/blob/881fdce8eb5a8bce2f1a846f79ac7142177e5b2a/src/GLib/gtype.jl#L405C1-L422

The segfault reported in #684 is possibly related.

I found this bug because I was reviewing the advice given in the manual for writing safe finalizers.
You can find a discussion of various strategies in that PR: JuliaLang/julia#51191

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions