1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/drb/drb.rb: Support graceful shutdown.

(DRbTCPSocket#initialize): Create a pipe for shutdown notification.
  (DRbTCPSocket#close): Invoke close_shutdown_pipe.
  (DRbTCPSocket#close_shutdown_pipe): New private method.
  (DRbTCPSocket#accept): Use accept_or_shutdown.
  (DRbTCPSocket#accept_or_shutdown): New private method which returns
  nil on shutdown.
  (DRbServer#stop_service): Use shutdown instead of Thread#kill.
  (DRbServer#run): Break infinite loop when main_loop returns nil.
  (DRbServer#main_loop): @protocol.accept may return nil.

* lib/drb/ssl.rb: Follow above change.

* lib/drb/unix.rb: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-09-21 17:06:05 +00:00
parent 941b101e22
commit 6a7d389ed0
4 changed files with 62 additions and 7 deletions

View file

@ -1,3 +1,20 @@
Mon Sep 22 02:04:25 2014 Tanaka Akira <akr@fsij.org>
* lib/drb/drb.rb: Support graceful shutdown.
(DRbTCPSocket#initialize): Create a pipe for shutdown notification.
(DRbTCPSocket#close): Invoke close_shutdown_pipe.
(DRbTCPSocket#close_shutdown_pipe): New private method.
(DRbTCPSocket#accept): Use accept_or_shutdown.
(DRbTCPSocket#accept_or_shutdown): New private method which returns
nil on shutdown.
(DRbServer#stop_service): Use shutdown instead of Thread#kill.
(DRbServer#run): Break infinite loop when main_loop returns nil.
(DRbServer#main_loop): @protocol.accept may return nil.
* lib/drb/ssl.rb: Follow above change.
* lib/drb/unix.rb: Ditto.
Sun Sep 21 13:54:36 2014 Masaki Matsushita <glass.saga@gmail.com>
* time.c: raise exception when minutes of utc_offset is out of 00-59.

View file

@ -905,6 +905,7 @@ module DRb
@acl = config[:tcp_acl]
@msg = DRbMessage.new(config)
set_sockopt(@socket)
@shutdown_pipe_r, @shutdown_pipe_w = IO.pipe
end
# Get the URI that we are connected to.
@ -952,14 +953,28 @@ module DRb
@socket.close
@socket = nil
end
close_shutdown_pipe
end
def close_shutdown_pipe
if @shutdown_pipe_r && !@shutdown_pipe_r.closed?
@shutdown_pipe_r.close
@shutdown_pipe_r = nil
end
if @shutdown_pipe_w && !@shutdown_pipe_w.closed?
@shutdown_pipe_w.close
@shutdown_pipe_w = nil
end
end
private :close_shutdown_pipe
# On the server side, for an instance returned by #open_server,
# accept a client connection and return a new instance to handle
# the server's side of this client-server session.
def accept
while true
s = @socket.accept
s = accept_or_shutdown
return nil unless s
break if (@acl ? @acl.allow_socket?(s) : true)
s.close
end
@ -971,6 +986,20 @@ module DRb
self.class.new(uri, s, @config)
end
def accept_or_shutdown
readables, = IO.select([@socket, @shutdown_pipe_r])
if readables.include? @shutdown_pipe_r
return nil
end
@socket.accept
end
private :accept_or_shutdown
# Graceful shutdown
def shutdown
@shutdown_pipe_w.close if @shutdown_pipe_w && !@shutdown_pipe_w.closed?
end
# Check to see if this connection is alive.
def alive?
return false unless @socket
@ -1438,7 +1467,12 @@ module DRb
if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
Thread.current['DRb']['stop_service'] = true
else
@thread.kill.join
if @protocol.respond_to? :shutdown
@protocol.shutdown
else
@thread.kill # xxx: Thread#kill
end
@thread.join
end
end
@ -1463,8 +1497,7 @@ module DRb
def run
Thread.start do
begin
while true
main_loop
while main_loop
end
ensure
@protocol.close if @protocol
@ -1607,7 +1640,9 @@ module DRb
# returning responses, until the client closes the connection
# or a local method call fails.
def main_loop
Thread.start(@protocol.accept) do |client|
client0 = @protocol.accept
return nil if !client0
Thread.start(client0) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
'server' => self }

View file

@ -322,7 +322,8 @@ module DRb
def accept # :nodoc:
begin
while true
soc = @socket.accept
soc = accept_or_shutdown
return nil unless soc
break if (@acl ? @acl.allow_socket?(soc) : true)
soc.close
end

View file

@ -98,10 +98,12 @@ module DRb
@socket.close
File.unlink(path) if @server_mode
@socket = nil
close_shutdown_pipe
end
def accept
s = @socket.accept
s = accept_or_shutdown
return nil unless s
self.class.new(nil, s, @config)
end