Code Monkey home page Code Monkey logo

Comments (6)

eregon avatar eregon commented on June 11, 2024 1

Thanks for the report.
That's very surprising, as Signal.trap("INT") {} should mean sending SIGINT should do nothing.

But actually with a little debugging what happens is ConditionVariable#wait has a spurious wakeup on CRuby (.wait returns even though neither .broadcast nor .signal has been called) in that case, probably because CRuby does SIGVTALRM/interrupt logic anyway it seems, even with the trap overridden.
Although even though the trap is overridden, it still has to execute that empty block on the main thread, so that's probably why we get that internal interrupt.
That's maybe a CRuby issue, because for instance there is no such issue on TruffleRuby.

We can workaround in


to use until instead of unless.
In most cases there should always be a loop around a ConditionVariable#wait, but since promises have a single state change that shouldn't be necessary.

from concurrent-ruby.

eregon avatar eregon commented on June 11, 2024 1

I reviewed all usages of ConditionVariable#wait in concurrent-ruby, they seem all fine.
In addition to #1016 there was also #1017 and #1018.
But as can be seen in #1017 sometimes it should not be a loop directly around the .wait.
So given we need the code only in one place it feels like the class is not necessary.
BTW, there is already

internally.

from concurrent-ruby.

907th avatar 907th commented on June 11, 2024

To reproduce:

# test.rb
require "concurrent-ruby"

Signal.trap("INT") {}

task = Concurrent::Promises.future do
  i = 0
  loop do
    i = (i + 1) % 10
  end
  i
end

puts task.value!
puts "Unexpected behaviour?" if task.pending?

Run in console:

❯ ruby ./test.rb
^C
Unexpected behaviour?

from concurrent-ruby.

eregon avatar eregon commented on June 11, 2024

CRuby issue for this: https://bugs.ruby-lang.org/issues/20047

from concurrent-ruby.

eregon avatar eregon commented on June 11, 2024

Fix in #1016

from concurrent-ruby.

bensheldon avatar bensheldon commented on June 11, 2024

@eregon what are you thoughts about making a private/internal class like ReliableConditionVariable that would wrap the loop/timeout fix for CRuby, or defer to the language recommendation? I wonder how many places this pattern should be duplicated... though hopefully a fix gets some traction in upstream CRuby too.

from concurrent-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.