Forum: Ruby-core [ruby-trunk - Bug #8616][Open] Process.daemon messes up threads

Be30361bb0b0c495e3077db43ad84b56?d=identicon&s=25 tenderlovemaking (Aaron Patterson) (Guest)
on 2013-07-10 00:30
(Received via mailing list)
Issue #8616 has been reported by tenderlovemaking (Aaron Patterson).

----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 Tanaka Akira (Guest)
on 2013-07-10 03:14
(Received via mailing list)
2013/7/10 tenderlovemaking (Aaron Patterson)
<aaron@tenderlovemaking.com>:
> Bug #8616: Process.daemon messes up threads
> https://bugs.ruby-lang.org/issues/8616

Process.daemon cannot preserve threads because
it uses fork and fork doesn't copy other threads.

Maybe, Process.daemon should raise an exception when
multi threads.
6f4ffc0ee2525e1a9b1127c1b84e579d?d=identicon&s=25 Evan Phoenix (Guest)
on 2013-07-10 03:31
(Received via mailing list)
No, it shouldn't raise an exception. Process.daemon and fork both use
after_fork() in C. That function should iterate all the threads and mark
them as KILLED since they are all dead.
85a7af756b7f36df3ae80a7cb448214e?d=identicon&s=25 benweint (Ben Weintraub) (Guest)
on 2013-09-25 01:06
(Received via mailing list)
Issue #8616 has been updated by benweint (Ben Weintraub).


I agree with Evan. The behavior he describes would be consistent with
how threads are handled when a process forks via Process.fork in Ruby.

See this example for a demonstration:
https://gist.github.com/benweint/6692546
----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-41961

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
85a7af756b7f36df3ae80a7cb448214e?d=identicon&s=25 benweint (Ben Weintraub) (Guest)
on 2013-09-25 05:56
(Received via mailing list)
Issue #8616 has been updated by benweint (Ben Weintraub).


Actually, it looks like this is fixed in Ruby 2.1.0-preview1
(Thread#alive? returns false for background threads spawned before a
call to Process.daemon), but still broken in 2.0.0-p247. Any chance of a
backport?
----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-41968

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
85a7af756b7f36df3ae80a7cb448214e?d=identicon&s=25 benweint (Ben Weintraub) (Guest)
on 2013-09-25 06:00
(Received via mailing list)
Issue #8616 has been updated by benweint (Ben Weintraub).


FWIW, it looks like the relevant change that fixed it for 2.1.0-preview1
was https://github.com/ruby/ruby/commit/300b7c80e
----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-41969

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-10-04 07:23
(Received via mailing list)
Issue #8616 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: UNKNOWN,
2.0.0: REQUIRED

I'll check r41910 to be backported later.

This ticket can be closed (for trunk)?
----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-42277

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: REQUIRED


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-10-04 17:10
(Received via mailing list)
Issue #8616 has been updated by nagachika (Tomoyuki Chikanaga).

Status changed from Open to Closed

I'll backport r41886, r41903 and r41910 to ruby_2_0_0.

Thank you for your notice!
----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-42289

Author: tenderlovemaking (Aaron Patterson)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: REQUIRED


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-10-04 18:28
(Received via mailing list)
Issue #8616 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 1.9.3: UNKNOWN, 2.0.0: REQUIRED to 1.9.3: UNKNOWN,
2.0.0: DONE

... and r40534 to resolve conflict.
merged r40534,r 41886  r41903, r41910 to ruby_2_0_0 at r43142.
----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-42291

Author: tenderlovemaking (Aaron Patterson)
Status: Closed
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
Backport: 1.9.3: UNKNOWN, 2.0.0: DONE


=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
8cbb39dadafaf2287a83a13ee4981ec9?d=identicon&s=25 unknown (Guest)
on 2014-01-30 12:47
(Received via mailing list)
Issue #8616 has been updated by Usaku NAKAMURA.

Backport changed from 1.9.3: UNKNOWN, 2.0.0: DONE to 1.9.3: DONE, 2.0.0:
DONE

backported into ruby_1_9_3 at r44766.

----------------------------------------
Bug #8616: Process.daemon messes up threads
https://bugs.ruby-lang.org/issues/8616#change-44829

* Author: Aaron Patterson
* Status: Closed
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: ruby 2.1.0dev (2013-07-10 trunk 41870) [x86_64-darwin12.4.0]
* Backport: 1.9.3: DONE, 2.0.0: DONE
----------------------------------------
=begin
Hi,

When I daemonize a process, it somehow messes up threads from the parent
process.  Here is a script to reproduce the problem:

  r1, w1 = IO.pipe
  r2, w2 = IO.pipe

  t = Thread.new {
    puts "start"
    w1.write "x"
    IO.select([r2])
    puts "alive"
  }

  IO.select([r1])
  Process.daemon true, true # comment this line out and everything works
  puts Process.pid
  w2.write "x"
  t.join
  puts "done"

If you run this program, there will be a ruby process in the background
that never dies.  If you comment out the "Process.daemon" line, the
script finishes.
=end
This topic is locked and can not be replied to.