grpc_kit 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/grpc_kit/server.rb +9 -9
- data/lib/grpc_kit/session/drain_controller.rb +14 -5
- data/lib/grpc_kit/session/server_session.rb +5 -4
- data/lib/grpc_kit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8fa450f3e7d2485f61e54edcbe6e664e63c5f4159c2f8c594600fa333a0eea0
|
4
|
+
data.tar.gz: 5bd5154135572f48b683683aad531631f346562efd4841abfbf1ad0b3e3f4f5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdd2a48377437970948468ac4ac9035dede0e79d8df6911416a44589d1e416b3470ac1b785784d8d37c80c89a0539859c736cbbf5952408b938fee9562543076
|
7
|
+
data.tar.gz: 1d6b13647c1f0ec44cfd0828b5c88b7d42375378654f27b35702f9ab6c90ce3e06c3ee9747eee3884b90dfdd6af957f0c5820dfa38a7cdf206a5d37e49f78649
|
data/lib/grpc_kit/server.rb
CHANGED
@@ -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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
data/lib/grpc_kit/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ds9
|