grpc_kit 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grpc_kit.rb +10 -5
- data/lib/grpc_kit/server.rb +7 -11
- data/lib/grpc_kit/session/client_session.rb +2 -6
- data/lib/grpc_kit/session/server_session.rb +15 -18
- data/lib/grpc_kit/transport/send_buffer.rb +0 -3
- 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: cb45ef9b949590a6d6f7892fc3ee999e18e986e702cf0404c2a8de8138c8b12e
|
4
|
+
data.tar.gz: 67efa185e194d7da4efd9fd8e1638d6ecd381b27e8572452fc337902d6969d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28418bf3d585a8b711ee7589ea2a591a834ec061802d97aa846242fd9ced64ed8ffda4179a1c25cf90ee2fbeaa1bba538c57932500da6ecb19eba7ab8b203e8f
|
7
|
+
data.tar.gz: 99be80c042bbf6b19d8c6385b8b778abfea9a2a007f22eeb1febbccc88a35d6646ba2df3fd5e915f7f9353a67b5581cc083540afc2484f46a717ef7d0c78ceea
|
data/lib/grpc_kit.rb
CHANGED
@@ -7,11 +7,16 @@ require 'grpc_kit/server'
|
|
7
7
|
require 'grpc_kit/client'
|
8
8
|
|
9
9
|
module GrpcKit
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
class << self
|
11
|
+
attr_writer :logger
|
12
|
+
|
13
|
+
def logger
|
14
|
+
@logger ||= Logger.new(STDOUT, level: ENV['GRPC_KIT_LOGLEVEL'] || :info)
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
# @params level [String] :debug, :info, :warn, :error, :fatal or :unknown
|
18
|
+
def self.loglevel=(level)
|
19
|
+
logger.level = level
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/grpc_kit/server.rb
CHANGED
@@ -36,14 +36,6 @@ module GrpcKit
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def wait_shutdown
|
40
|
-
loop do
|
41
|
-
return if @stopping
|
42
|
-
|
43
|
-
sleep 1
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
39
|
def force_shutdown
|
48
40
|
# expected to be called in trap context
|
49
41
|
Thread.new do
|
@@ -60,10 +52,12 @@ module GrpcKit
|
|
60
52
|
Thread.new do
|
61
53
|
GrpcKit.logger.debug('graceful shutdown')
|
62
54
|
@mutex.synchronize { @sessions.each(&:drain) }
|
55
|
+
@stopping = true
|
56
|
+
|
63
57
|
begin
|
64
58
|
Timeout.timeout(@max_graceful_wait) do
|
65
59
|
loop do
|
66
|
-
break if @
|
60
|
+
break if @sessions.empty?
|
67
61
|
|
68
62
|
sleep 1
|
69
63
|
end
|
@@ -71,11 +65,13 @@ module GrpcKit
|
|
71
65
|
rescue Timeout::Error => _
|
72
66
|
GrpcKit.logger.debug('Max wait time expired')
|
73
67
|
end
|
74
|
-
|
75
|
-
@stopping = true
|
76
68
|
end
|
77
69
|
end
|
78
70
|
|
71
|
+
def session_count
|
72
|
+
@mutex.synchronize { @sessions.size }
|
73
|
+
end
|
74
|
+
|
79
75
|
# @params path [String]
|
80
76
|
# @params stream [GrpcKit::Streams::ServerStream]
|
81
77
|
def dispatch(path, stream)
|
@@ -24,7 +24,6 @@ module GrpcKit
|
|
24
24
|
@opts = opts
|
25
25
|
@draining = false
|
26
26
|
@stop = false
|
27
|
-
@last_stream_id = 0
|
28
27
|
end
|
29
28
|
|
30
29
|
def send_request(data, headers)
|
@@ -84,11 +83,9 @@ module GrpcKit
|
|
84
83
|
shutdown
|
85
84
|
raise e
|
86
85
|
rescue DS9::Exception => e
|
87
|
-
|
86
|
+
GrpcKit.logger.debug(e.message)
|
88
87
|
if DS9::ERR_EOF == e.code
|
89
|
-
|
90
|
-
return
|
91
|
-
# raise EOFError
|
88
|
+
raise EOFError, e
|
92
89
|
end
|
93
90
|
|
94
91
|
raise e
|
@@ -185,7 +182,6 @@ module GrpcKit
|
|
185
182
|
@streams.each_value(&:drain)
|
186
183
|
end
|
187
184
|
|
188
|
-
@last_stream_id = last_stream_id
|
189
185
|
@streams.each do |id, stream|
|
190
186
|
if id > last_stream_id
|
191
187
|
stream.close
|
@@ -31,27 +31,22 @@ module GrpcKit
|
|
31
31
|
def start
|
32
32
|
@io.wait_readable
|
33
33
|
loop do
|
34
|
-
break if @stop
|
35
|
-
|
36
34
|
invoke
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
elsif @peer_shutdowned && !want_write?
|
41
|
-
break
|
42
|
-
end
|
43
|
-
|
44
|
-
run_once
|
36
|
+
continue = run_once
|
37
|
+
break unless continue
|
45
38
|
end
|
46
|
-
rescue Errno::ECONNRESET, IOError => e
|
47
|
-
GrpcKit.logger.debug(e.message)
|
48
|
-
shutdown
|
49
39
|
ensure
|
50
40
|
GrpcKit.logger.debug('Finish server session')
|
51
41
|
end
|
52
42
|
|
43
|
+
# @return [bool] return session can continue
|
53
44
|
def run_once
|
54
|
-
|
45
|
+
if @peer_shutdowned || @stop || !(want_read? || want_write?)
|
46
|
+
# it could be called twice
|
47
|
+
@streams.each_value(&:close)
|
48
|
+
return false
|
49
|
+
end
|
55
50
|
|
56
51
|
if @drain
|
57
52
|
if @streams.empty?
|
@@ -69,6 +64,12 @@ module GrpcKit
|
|
69
64
|
if want_write?
|
70
65
|
send
|
71
66
|
end
|
67
|
+
|
68
|
+
true
|
69
|
+
rescue Errno::ECONNRESET, IOError => e
|
70
|
+
GrpcKit.logger.debug(e.message)
|
71
|
+
shutdown
|
72
|
+
false
|
72
73
|
end
|
73
74
|
|
74
75
|
def drain
|
@@ -98,9 +99,6 @@ module GrpcKit
|
|
98
99
|
|
99
100
|
def do_read
|
100
101
|
receive
|
101
|
-
rescue IOError => e
|
102
|
-
shutdown
|
103
|
-
raise e
|
104
102
|
rescue DS9::Exception => e
|
105
103
|
shutdown
|
106
104
|
if DS9::ERR_EOF == e.code
|
@@ -153,9 +151,8 @@ module GrpcKit
|
|
153
151
|
if frame.ping_ack?
|
154
152
|
GrpcKit.logger.debug('ping ack is received')
|
155
153
|
# nghttp2 can't send any data once server sent actaul GoAway(not shutdown notice) frame.
|
156
|
-
# We want to send data in
|
154
|
+
# We want to send data in case of ClientStreamer or BidiBstreamer which they are sending data in same stream
|
157
155
|
# So we have to wait to send actual GoAway frame untill timeout or something
|
158
|
-
|
159
156
|
# @drain.recv_ping_ack if @drain
|
160
157
|
end
|
161
158
|
# when DS9::Frames::Goaway
|
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.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ganmacs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ds9
|