ruby-concurrency / ruby-concurrency/concurrent-ruby
Concurrent::Promises::Channel deadlock in example code
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 5.8k
- Forks
- 420
- Avg merge
- 20h 45m
- Merged PRs (30d)
- 4
Description
I'm running example from Promises::Channel docs.
channel = Concurrent::Promises::Channel.new 2
log = Concurrent::Array.new # => []
def produce(channel, log, producer, i)
log.push format "producer %d pushing %d", producer, i
channel.push_op([producer, i]).then do
i + 1 < 4 ? produce(channel, log, producer, i + 1) : :done
end
end # => :produce
def consume(channel, log, consumer, i)
channel.pop_op.then(consumer, i) do |(from, message), consumer, i|
log.push format "consumer %d got %d. payload %d from producer %d",
consumer, i, message, from
do_stuff
i + 1 < 2 ? consume(channel, log, consumer, i + 1) : :done
end
end # => :consume
producers = Array.new 2 do |i|
Concurrent::Promises.future(channel, log, i) { |*args| produce *args, 0 }.run
end
consumers = Array.new 4 do |i|
Concurrent::Promises.future(channel, log, i) { |*args| consume *args, 0 }.run
end
producers.map(&:value!) # => [:done, :done]
consumers.map(&:value!) # => [:done, :done, :done, :done]
log
and it returns error:
<home>/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/promises.rb:775:in 'sleep': No live threads left. Deadlock? (fatal)
* Operating system: mac
* Ruby implementation: Ruby MRI 2.7.0
* `concurrent-ruby` version: 1.1.6
* `concurrent-ruby-ext` installed: yes
* `concurrent-ruby-edge` used: yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Promises::Channel documentation example with Ruby MRI 2.7.0 and concurrent-ruby 1.1.6, then inspect concurrent/promises.rb around line 775 where the deadlock is reported. Determine why the example leaves no live threads and verify that the documented example completes without the fatal deadlock.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100