Skip to content

Fix Ractor IsolationError with file and thread safety enabled #22

@bkuhlmann

Description

@bkuhlmann

Why

Hello. 👋 With the release of Version 0.2.0, especially this commit, you'll now get a Ractor::IsolationError when writing data.

How

Here's the quickest way I could reproduce this:

#! /usr/bin/env ruby
# frozen_string_literal: true

# Save as `demo`, then `chmod 755 demo`, and run as `./demo`.

require "bundler/inline"

gemfile true do
  source "https://rubygems.org"

  gem "amazing_print"
  gem "debug"
  gem "lode"
  gem "milestoner"
end

client = Lode.new "demo.store" do |config|
  config.mode = :max
  config.table = Lode::Tables::Value
  config.register :users, model: Milestoner::Models::User, primary_key: :name
end

creator = Milestoner::CLI::Actions::Cache::Create.new(client:)
creator.call "1,zoe,Zoë Washburne"

The above will produce this error:

Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
<internal:ractor>:832:in 'Ractor.make_shareable': Proc's self is not shareable: #<Proc:0x0000000160ea17d8 /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/pstore-0.2.0/lib/pstore.rb:673> (Ractor::IsolationError)
	from /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/pstore-0.2.0/lib/pstore.rb:676:in 'PStore#on_windows?'
	from /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/pstore-0.2.0/lib/pstore.rb:685:in 'PStore#save_data'
	from /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/pstore-0.2.0/lib/pstore.rb:575:in 'PStore#transaction'
	from /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/lode-2.2.0/lib/lode/client.rb:34:in 'Lode::Client#transact'
	from /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/lode-2.2.0/lib/lode/client.rb:27:in 'Lode::Client#write'
	from /Users/bkuhlmann/.cache/frum/versions/3.4.2/lib/ruby/gems/3.4.0/gems/milestoner-19.3.0/lib/milestoner/cli/actions/cache/create.rb:23:in 'Milestoner::CLI::Actions::Cache::Create#call'
	from /Users/bkuhlmann/Engineering/Misc/demo:23:in '<main>'

The Lode gem is monadic wrapper around PStore so if you remove config.mode = :max. The issue goes away. The max mode simply wraps PStore's native functionality of ultra_safe = true. In other words, this is equivalent to:

PStore.new("demo.store", true).tap { it.ultra_safe = true }

So you can't use PStore with thread and file safety at the same time anymore?

Notes

If this line is removed, the issue goes away.

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