grpc_kit 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 429df1d2acc2083513f55a3b12dc612e0f27b2ae0a7fb13b198bc304294d6f75
4
- data.tar.gz: 482c39c5674efbf8a08c6deadb93eea903078460d2eba85532728d7ddeb58a80
3
+ metadata.gz: d8fa450f3e7d2485f61e54edcbe6e664e63c5f4159c2f8c594600fa333a0eea0
4
+ data.tar.gz: 5bd5154135572f48b683683aad531631f346562efd4841abfbf1ad0b3e3f4f5f
5
5
  SHA512:
6
- metadata.gz: 036c1f0bba4959a1a6a0aa0f060251bae8ea6624872f2a17b636ce1c5aa1fd5168a0f7ad12340ee2a71a7954088ca98d02b11455d6fb5c3adc523617d3bb5004
7
- data.tar.gz: 2b99be0aeedd437596ad8a94b25f25ddf06f45c2dbccad6da55e3bc27b339184c6dfe6d7c4ccca561f1f296f0369fa711042ce904e8bcf1b55c611e5da85ec34
6
+ metadata.gz: cdd2a48377437970948468ac4ac9035dede0e79d8df6911416a44589d1e416b3470ac1b785784d8d37c80c89a0539859c736cbbf5952408b938fee9562543076
7
+ data.tar.gz: 1d6b13647c1f0ec44cfd0828b5c88b7d42375378654f27b35702f9ab6c90ce3e06c3ee9747eee3884b90dfdd6af957f0c5820dfa38a7cdf206a5d37e49f78649
@@ -64,23 +64,23 @@ module GrpcKit
64
64
  end
65
65
 
66
66
  # This method is expected to be called in trap context
67
+ # @params timeout [Boolean] timeout error could be raised or not
67
68
  # @return [void]
68
- def graceful_shutdown
69
+ def graceful_shutdown(timeout: true)
69
70
  @stopping = true
70
71
 
71
72
  Thread.new do
72
73
  GrpcKit.logger.debug('graceful shutdown')
73
74
  @mutex.synchronize { @sessions.each(&:drain) }
74
75
 
75
- end_time = Time.now + @shutdown_timeout
76
- loop do
77
- if end_time < Time.now
78
- GrpcKit.logger.error("Graceful shutdown is timeout (#{@shutdown_timeout}sec). Perform shutdown forceibly")
79
- shutdown_sessions
80
- break
81
- elsif @sessions.empty?
82
- break
76
+ begin
77
+ sec = timeout ? @shutdown_timeout : 0
78
+ Timeout.timeout(sec) do
79
+ sleep 1 until @sessions.empty?
83
80
  end
81
+ rescue Timeout::Error => _
82
+ GrpcKit.logger.error("Graceful shutdown is timeout (#{@shutdown_timeout}sec). Perform shutdown forceibly")
83
+ shutdown_sessions
84
84
  end
85
85
  end
86
86
  end
@@ -8,12 +8,14 @@ module GrpcKit
8
8
  module Status
9
9
  NOT_START = 0
10
10
  STARTED = 1
11
- SENT_PING = 2
12
- RECV_PING_ACK = 3
13
- SENT_GOAWAY = 4
11
+ SENT_SHUTDOWN = 2
12
+ SENT_PING = 3
13
+ RECV_PING_ACK = 4
14
+ SENT_GOAWAY = 5
14
15
  end
15
16
 
16
- def initialize
17
+ def initialize(draining_time = 5)
18
+ @draining_time = draining_time
17
19
  @status = Status::NOT_START
18
20
  end
19
21
 
@@ -39,15 +41,22 @@ module GrpcKit
39
41
  # next_step
40
42
  when Status::STARTED
41
43
  session.submit_shutdown
44
+ next_step
45
+ when Status::SENT_SHUTDOWN
42
46
  session.submit_ping
47
+ @sent_time = Time.now.to_i
43
48
  next_step
44
49
  when Status::SENT_PING
45
50
  # skip until #recv_ping_ack is called (1RTT)
46
51
  when Status::RECV_PING_ACK
52
+ if @sent_time && (Time.now.to_i - @sent_time) > @draining_time
53
+ return
54
+ end
55
+
47
56
  session.submit_goaway(DS9::NO_ERROR, session.last_proc_stream_id)
48
57
  next_step
49
58
  when Status::SENT_GOAWAY
50
- session.shutdown
59
+ # session.shutdown
51
60
  end
52
61
  end
53
62
 
@@ -54,6 +54,10 @@ module GrpcKit
54
54
  return false
55
55
  end
56
56
 
57
+ if @drain_controller.start_draining?
58
+ @drain_controller.next(self)
59
+ end
60
+
57
61
  rs, ws = @io.select
58
62
 
59
63
  if !rs.empty? && want_read?
@@ -178,10 +182,7 @@ module GrpcKit
178
182
  when DS9::Frames::Ping
179
183
  if frame.ping_ack?
180
184
  GrpcKit.logger.debug('ping ack is received')
181
- # nghttp2 can't send any data once server sent actaul GoAway(not shutdown notice) frame.
182
- # We want to send data in case of ClientStreamer or BidiBstreamer which they are sending data in same stream
183
- # So we have to wait to send actual GoAway frame untill timeout or something
184
- # @drain_controller.recv_ping_ack
185
+ @drain_controller.recv_ping_ack
185
186
  end
186
187
  # when DS9::Frames::Goaway
187
188
  # when DS9::Frames::RstStream
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrpcKit
4
- VERSION = '0.3.5'
4
+ VERSION = '0.3.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Iwama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-07 00:00:00.000000000 Z
11
+ date: 2019-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ds9