ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:93652] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock
       [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
@ 2019-07-10  6:55 ` naruse
  2019-08-18  4:33 ` [ruby-core:94407] " nagachika00
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: naruse @ 2019-07-10  6:55 UTC (permalink / raw)
  To: ruby-core

Issue #15992 has been reported by naruse (Yui NARUSE).

----------------------------------------
Bug #15992: An exception breaks monitor state and cause deadlock
https://bugs.ruby-lang.org/issues/15992

* Author: naruse (Yui NARUSE)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: REQUIRED, 2.6: REQUIRED
----------------------------------------
lib/monitor.rb provides Monitor.
But its state handling is weak for interrupts caused by Thread.kill for example timeout libraries.

Timeout exception may happen everywhere. If it raised when the thread is executing

```ruby
  def mon_exit
    mon_check_owner
    @mon_count -=1
    if @mon_count == 0
      @mon_owner = nil
      # HERE!!!
      @mon_mutex.unlock
    end
  end
``` 

It breaks the state of the monitor and it causes deadlock.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94407] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock
       [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
  2019-07-10  6:55 ` [ruby-core:93652] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock naruse
@ 2019-08-18  4:33 ` nagachika00
  2019-08-21  9:51 ` [ruby-core:94456] " nagachika00
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: nagachika00 @ 2019-08-18  4:33 UTC (permalink / raw)
  To: ruby-core

Issue #15992 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: REQUIRED, 2.6: REQUIRED to 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67742 merged revision(s) f91879a7b548284c93743168acfd11e3d2aeefac.

----------------------------------------
Bug #15992: An exception breaks monitor state and cause deadlock
https://bugs.ruby-lang.org/issues/15992#change-80827

* Author: naruse (Yui NARUSE)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: REQUIRED, 2.6: DONE
----------------------------------------
lib/monitor.rb provides Monitor.
But its state handling is weak for interrupts caused by Thread.kill for example timeout libraries.

Timeout exception may happen everywhere. If it raised when the thread is executing

```ruby
  def mon_exit
    mon_check_owner
    @mon_count -=1
    if @mon_count == 0
      @mon_owner = nil
      # HERE!!!
      @mon_mutex.unlock
    end
  end
``` 

It breaks the state of the monitor and it causes deadlock.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94456] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock
       [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
  2019-07-10  6:55 ` [ruby-core:93652] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock naruse
  2019-08-18  4:33 ` [ruby-core:94407] " nagachika00
@ 2019-08-21  9:51 ` nagachika00
  2019-08-22 11:28 ` [ruby-core:94478] " nagachika00
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: nagachika00 @ 2019-08-21  9:51 UTC (permalink / raw)
  To: ruby-core

Issue #15992 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: REQUIRED, 2.6: DONE to 2.5: REQUIRED, 2.6: REQUIRED

9557069299ac3b96691040a541afa65761a724ad is a follow up commit to ease memory consumption impact of f91879a7b548284c93743168acfd11e3d2aeefac. I think it should be backported too.

----------------------------------------
Bug #15992: An exception breaks monitor state and cause deadlock
https://bugs.ruby-lang.org/issues/15992#change-80887

* Author: naruse (Yui NARUSE)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: REQUIRED, 2.6: REQUIRED
----------------------------------------
lib/monitor.rb provides Monitor.
But its state handling is weak for interrupts caused by Thread.kill for example timeout libraries.

Timeout exception may happen everywhere. If it raised when the thread is executing

```ruby
  def mon_exit
    mon_check_owner
    @mon_count -=1
    if @mon_count == 0
      @mon_owner = nil
      # HERE!!!
      @mon_mutex.unlock
    end
  end
``` 

It breaks the state of the monitor and it causes deadlock.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94478] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock
       [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-21  9:51 ` [ruby-core:94456] " nagachika00
@ 2019-08-22 11:28 ` nagachika00
  2019-08-26 17:03 ` [ruby-core:94583] " usa
  2019-08-26 22:22 ` [ruby-core:94591] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: nagachika00 @ 2019-08-22 11:28 UTC (permalink / raw)
  To: ruby-core

Issue #15992 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: REQUIRED, 2.6: REQUIRED to 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67749 merged revision(s) 9557069299ac3b96691040a541afa65761a724ad.

----------------------------------------
Bug #15992: An exception breaks monitor state and cause deadlock
https://bugs.ruby-lang.org/issues/15992#change-80913

* Author: naruse (Yui NARUSE)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: REQUIRED, 2.6: DONE
----------------------------------------
lib/monitor.rb provides Monitor.
But its state handling is weak for interrupts caused by Thread.kill for example timeout libraries.

Timeout exception may happen everywhere. If it raised when the thread is executing

```ruby
  def mon_exit
    mon_check_owner
    @mon_count -=1
    if @mon_count == 0
      @mon_owner = nil
      # HERE!!!
      @mon_mutex.unlock
    end
  end
``` 

It breaks the state of the monitor and it causes deadlock.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94583] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock
       [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-08-22 11:28 ` [ruby-core:94478] " nagachika00
@ 2019-08-26 17:03 ` usa
  2019-08-26 22:22 ` [ruby-core:94591] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: usa @ 2019-08-26 17:03 UTC (permalink / raw)
  To: ruby-core

Issue #15992 has been updated by usa (Usaku NAKAMURA).

Backport changed from 2.5: REQUIRED, 2.6: DONE to 2.5: DONE, 2.6: DONE

ruby_2_5 r67774 merged revision(s) f91879a7b548284c93743168acfd11e3d2aeefac,9557069299ac3b96691040a541afa65761a724ad.

----------------------------------------
Bug #15992: An exception breaks monitor state and cause deadlock
https://bugs.ruby-lang.org/issues/15992#change-81046

* Author: naruse (Yui NARUSE)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: DONE, 2.6: DONE
----------------------------------------
lib/monitor.rb provides Monitor.
But its state handling is weak for interrupts caused by Thread.kill for example timeout libraries.

Timeout exception may happen everywhere. If it raised when the thread is executing

```ruby
  def mon_exit
    mon_check_owner
    @mon_count -=1
    if @mon_count == 0
      @mon_owner = nil
      # HERE!!!
      @mon_mutex.unlock
    end
  end
``` 

It breaks the state of the monitor and it causes deadlock.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94591] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock
       [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-08-26 17:03 ` [ruby-core:94583] " usa
@ 2019-08-26 22:22 ` eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-08-26 22:22 UTC (permalink / raw)
  To: ruby-core

Issue #15992 has been updated by Eregon (Benoit Daloze).


Should `mon_enter` and `mon_exit` use `Thread.handle_interrupt` inside their method definitions, so they are safe when called directly too?

`Thread.handle_interrupt(Exception => :never)` seems too much for `mon_enter`, I think `Thread.handle_interrupt(Exception => :blocking)` would be better.
Otherwise, it's not possible to interrupt a thread trying to get a contended monitor with `Thread#raise`:
```
ruby -rmonitor -e 'o=Object.new.extend(MonitorMixin); Thread.new{ o.mon_enter; sleep }; sleep 0.1; Thread.new{sleep 3; p :kill; Thread.main.raise "bye"}; p o.synchronize { p :in; sleep }'
```
Never exits on trunk, but it does exit on 2.6.2 and before. Even Thread#kill does not help.

Ctrl+C does interrupt it, because signal traps are not yet supported by `handle_interrupt`, but that might change.

----------------------------------------
Bug #15992: An exception breaks monitor state and cause deadlock
https://bugs.ruby-lang.org/issues/15992#change-81063

* Author: naruse (Yui NARUSE)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: DONE, 2.6: DONE
----------------------------------------
lib/monitor.rb provides Monitor.
But its state handling is weak for interrupts caused by Thread.kill for example timeout libraries.

Timeout exception may happen everywhere. If it raised when the thread is executing

```ruby
  def mon_exit
    mon_check_owner
    @mon_count -=1
    if @mon_count == 0
      @mon_owner = nil
      # HERE!!!
      @mon_mutex.unlock
    end
  end
``` 

It breaks the state of the monitor and it causes deadlock.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-26 22:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15992.20190710065540@ruby-lang.org>
2019-07-10  6:55 ` [ruby-core:93652] [Ruby master Bug#15992] An exception breaks monitor state and cause deadlock naruse
2019-08-18  4:33 ` [ruby-core:94407] " nagachika00
2019-08-21  9:51 ` [ruby-core:94456] " nagachika00
2019-08-22 11:28 ` [ruby-core:94478] " nagachika00
2019-08-26 17:03 ` [ruby-core:94583] " usa
2019-08-26 22:22 ` [ruby-core:94591] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).