yahns Ruby server user/dev discussion
 help / color / mirror / Atom feed
1b65e3d41ad6f9dbbe0623f29543539ba0c4a800 blob 2223 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
# -*- encoding: binary -*-
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
class Yahns::Worker # :nodoc:
  attr_accessor :nr
  attr_reader :to_io

  def initialize(nr)
    @nr = nr
    @to_io, @wr = Kgio::Pipe.new

    # Seems it's only alpha with a != 4K page size on Linux
    begin
      # F_SETPIPE_SZ = 1031, PAGE_SIZE = 4096
      @to_io.fcntl(1031, 4096)
    rescue Errno::EINVAL
      # old kernel
    end if RUBY_PLATFORM =~ /\blinux\b/ && RUBY_PLATFORM !~ /alpha/
  end

  def atfork_child
    @wr = @wr.close # nil @wr to save space in worker process
  end

  def atfork_parent
    @to_io = @to_io.close
    self
  end

  # used in the worker process.
  # This causes the worker to gracefully exit if the master
  # dies unexpectedly.
  def yahns_step
    case buf = @to_io.kgio_tryread(4)
    when String
      # unpack the buffer and trigger the signal handler
      signum = buf.unpack('l')
      fake_sig(signum[0])
      # keep looping, more signals may be queued
    when nil # EOF: master died, but we are at a safe place to exit
      fake_sig(:QUIT)
      @to_io.close
      return :ignore
    when :wait_readable # keep waiting
      return :ignore
    end while true # loop, as multiple signals may be sent
  end

  # worker objects may be compared to just plain Integers
  def ==(other_nr) # :nodoc:
    @nr == other_nr
  end

  # call a signal handler immediately without triggering EINTR
  # We do not use the more obvious Process.kill(sig, $$) here since
  # that signal delivery may be deferred.  We want to avoid signal delivery
  # while the Rack app.call is running because some database drivers
  # (e.g. ruby-pg) may cancel pending requests.
  def fake_sig(sig) # :nodoc:
    old_cb = trap(sig, "IGNORE")
    old_cb.call
  ensure
    trap(sig, old_cb)
  end

  # master sends fake signals to children
  def soft_kill(signum) # :nodoc:
    # writing and reading 4 bytes on a pipe is atomic on all POSIX platforms
    # Do not care in the odd case the buffer is full, here.
    @wr.kgio_trywrite([signum].pack('l'))
  rescue Errno::EPIPE
    # worker will be reaped soon
  end
end
debug log:

solving 1b65e3d ...
found 1b65e3d in https://yhbt.net/yahns.git

yahns Ruby server user/dev discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 yahns-public yahns-public/ https://yhbt.net/yahns-public \
		yahns-public@yhbt.net yahns-public@rubyforge.org
	public-inbox-index yahns-public

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	../../../yahns.git

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git