ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: charlie@atech.media
To: ruby-core@ruby-lang.org
Subject: [ruby-core:82418] [Ruby trunk Bug#13794] Infinite loop of sched_yield
Date: Thu, 17 Aug 2017 15:08:42 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-66219.20170817150841.b744fe6f65112d7d@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13794.20170809152106@ruby-lang.org

Issue #13794 has been updated by catphish (Charlie Smurthwaite).

File sched_yield_1.patch added

The patch above does not work because native_reset_timer_thread runs after fork in the parent. Attached an alternative patch that runs in gvl_atfork and appears not to run in the parent. Again I do not believe this is necessarily the correct way to fix this but I am also looking for something that works for me i the meantime.

Comments appreciated.

----------------------------------------
Bug #13794: Infinite loop of sched_yield
https://bugs.ruby-lang.org/issues/13794#change-66219

* Author: catphish (Charlie Smurthwaite)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
I have been encountering an issue with processes hanging in an infinite loop of calling sched_yield(). The looping code can be found at https://github.com/ruby/ruby/blob/v2_3_4/thread_pthread.c#L1663

while (ATOMIC_CAS(timer_thread_pipe.writing, (rb_atomic_t)0, 0)) {
  native_thread_yield();
}

It is my belief that by some mechanism I have not been able to identify, timer_thread_pipe.writing is incremented but it never decremented, causing this loop to run infinitely.

I am not able to create a reproducible test case, however this issue occurs regularly in my production application. I have attached backtraces and thread lists from 2 processes exhibiting this behaviour. gdb confirms that timer_thread_pipe.writing = 1 in these processes.

I believe one possibility of the cause is that rb_thread_wakeup_timer_thread() or rb_thread_wakeup_timer_thread_low() is called, and before it returns, another thread calls fork(), leaving the value of timer_thread_pipe.writing incremented, but leaving behind the thread that would normally decrement it.

If this is correct, one solution would be to reset timer_thread_pipe.writing to 0 in native_reset_timer_thread() immediately after a fork.

Other examples of similar bugs being reported:
https://github.com/resque/resque/issues/578
https://github.com/zk-ruby/zk/issues/50

---Files--------------------------------
backtrace_1.txt (14 KB)
backtrace_2.txt (10.9 KB)
sched_yield_1.patch (738 Bytes)


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

  parent reply	other threads:[~2017-08-17 15:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-13794.20170809152106@ruby-lang.org>
2017-08-09 15:21 ` [ruby-core:82311] [Ruby trunk Bug#13794] Infinite loop of sched_yield charlie
2017-08-09 17:07   ` [ruby-core:82314] " Eric Wong
2017-08-09 23:33   ` [ruby-core:82319] " Eric Wong
2017-08-09 23:38     ` [ruby-core:82320] " Eric Wong
2017-08-09 23:49 ` [ruby-core:82321] " charlie
2017-08-28 23:51   ` [ruby-core:82495] " Eric Wong
2017-08-09 23:56 ` [ruby-core:82322] " charlie
2017-08-15 12:04 ` [ruby-core:82386] " charlie
2017-08-17 11:57 ` [ruby-core:82414] " charlie
2017-08-17 15:07 ` [ruby-core:82417] " charlie
2017-08-17 15:08 ` charlie [this message]
2017-08-23  0:04   ` [ruby-core:82452] " Eric Wong
2017-08-29 10:17 ` [ruby-core:82510] " charlie
2017-09-01 16:09 ` [ruby-core:82626] " charlie
2017-09-29 10:20 ` [ruby-core:83061] " greg.potamianos
2017-09-30  3:21 ` [ruby-core:83064] " xkernigh
2017-09-30 21:54   ` [ruby-core:83067] " Eric Wong
2017-10-01  2:32   ` [ruby-core:83069] " Eric Wong
2017-10-19 10:51 ` [ruby-core:83392] " charlie
2018-01-08 10:26 ` [ruby-core:84699] " charlie
2018-01-15 13:27 ` [ruby-core:84870] " nagachika00
2018-01-31 13:49 ` [ruby-core:85307] " usa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-66219.20170817150841.b744fe6f65112d7d@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).