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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cd6355c75605e749f1590fa3f3f3346f5d77288753df21cd104c9af78d22f5f
4
- data.tar.gz: 3e6d0c8606b0476edaca281b510b1c8d1f047df7accc479e2b1e569567869497
3
+ metadata.gz: cb45ef9b949590a6d6f7892fc3ee999e18e986e702cf0404c2a8de8138c8b12e
4
+ data.tar.gz: 67efa185e194d7da4efd9fd8e1638d6ecd381b27e8572452fc337902d6969d3d
5
5
  SHA512:
6
- metadata.gz: bde53f9753f23d273ed4b211c63f2e4727e88c8d67b9b330add41c9bec5b82ebbe884c551c496c5fcdca57252e36d58660ac5a70f31ecd8cb84f00258a6972f9
7
- data.tar.gz: 75d4b9b74c7cc99111c348c754c79cda00295745485ee6d28a4e0aa492bc28bcc6303dd04bbd95320a483a3bc8559840c79be09621eabb04bfb853b7e7be9760
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
- def self.logger
11
- @logger ||= Logger.new(STDOUT, level: :debug)
12
- end
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
- def self.logger=(logger)
15
- @logger = logger
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
@@ -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 @mutex.synchronize { @sessions.empty? }
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
- shutdown
86
+ GrpcKit.logger.debug(e.message)
88
87
  if DS9::ERR_EOF == e.code
89
- @peer_shutdowned = true
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
- if !want_read? && !want_write?
39
- break
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
- return if @stop
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 this case when ClientStreamer or BidiBstreamer which they are sending data in same stream
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
@@ -5,7 +5,6 @@ module GrpcKit
5
5
  class SendBuffer
6
6
  def initialize
7
7
  @buffer = nil
8
- @pos = 0
9
8
  @end_write = false
10
9
  end
11
10
 
@@ -17,8 +16,6 @@ module GrpcKit
17
16
  else
18
17
  @buffer = data
19
18
  end
20
-
21
- data.size
22
19
  end
23
20
 
24
21
  def end_write
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrpcKit
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.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.1.5
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-02 00:00:00.000000000 Z
11
+ date: 2018-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ds9