Skip to content

SharedChan can be used to create cycles #10835

Closed
@bill-myers

Description

@bill-myers

Here is how one does it:

  1. Create channels A and B
  2. Send a clone of A's SharedChan and send A's port to channel B
  3. Send a clone of B's SharedChan and send B's port to channel A
  4. Drop the original SharedChans
  5. Memory leak!

The Linux kernel has the exact same issue with file descriptor passing on Unix sockets and they solve it with an global in-kernel garbage collector for unix sockets (http://lxr.free-electrons.com/source/net/unix/garbage.c)

Rust can't do the GC approach easily because it can pass structures containing SharedChans in addition to just SharedChan like Linux.

However, we can prevent cycles just like we do for RWARC: by adding a Freeze bound to SharedChan's T and making sure SharedChan is no_freeze.

Should this be done?

If not, why shouldn't the Freeze be removed from RWARC too, since they are effectively equivalent functionality? (method calls on RWARC-protected objects are equivalent to sending a message via SharedChan to a task that calls the corresponding method)

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