gritz-native 0.9.0 → 0.9.1
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/CHANGELOG.md +7 -0
- data/lib/gritz/native/version.rb +1 -1
- data/lib/gritz/transport/native/bridge.rb +4 -0
- data/lib/gritz/transport/native/cancellation.rb +86 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b74d5378f2389a62bfaa76d68daddac7fe2b08b5d54fe55931baa2d0ef352c0
|
|
4
|
+
data.tar.gz: c546ba1e709dd568c352519cfd13da38f6faf7d79aba0caaaef7a65f9e48399f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9483adad6e9e3d786113332e072c45232ad5bf2f0bcb432a9e022b1bd7aea689ebebe36001b918ce8785793e2591ee94cb6b4a71049cb3f6fbc2e9c76c5733cc
|
|
7
|
+
data.tar.gz: 8bd205690359103b323c819e0d2f24a3654c4a4e1e9048bee93e2757d45a5aaf36b326a580b46640e4ddcf130491a974c7f2ba4dd8e6ad199389e19503b6dc3f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
- Observe client cancellation while unary and streaming controllers are running, so `Context#check_cancelled!` releases the occupied pool slot.
|
|
6
|
+
- Release close observers during normal responses, errors and shutdown without reporting successful calls as cancelled.
|
|
7
|
+
- Cancellation observation adds a short-lived thread per admitted application RPC; fixed-runner overhead validation remains pending.
|
|
8
|
+
- Require Gritz Core 0.9.1 for operational commands and corrected master readiness timeouts.
|
|
9
|
+
|
|
3
10
|
## 0.9.0
|
|
4
11
|
|
|
5
12
|
- Require Gritz Core 0.9.0 for startup TLS-file validation and the stabilization support policy.
|
data/lib/gritz/native/version.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "cancellation"
|
|
4
|
+
|
|
3
5
|
module Gritz
|
|
4
6
|
module Transport
|
|
5
7
|
class Native
|
|
@@ -10,6 +12,8 @@ module Gritz
|
|
|
10
12
|
Class.new(service_class) do
|
|
11
13
|
self.service_name = service_class.service_name
|
|
12
14
|
descriptors.each do |descriptor|
|
|
15
|
+
rpc_name = descriptor.name.to_sym
|
|
16
|
+
rpc_descs[rpc_name] = Cancellation::Descriptor.new(*rpc_descs.fetch(rpc_name).to_a)
|
|
13
17
|
case descriptor.kind
|
|
14
18
|
when :client_streaming
|
|
15
19
|
define_method(descriptor.action) do |view|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gritz
|
|
4
|
+
module Transport
|
|
5
|
+
class Native
|
|
6
|
+
# grpc's server views read a client-status field which is never populated
|
|
7
|
+
# during a server handler. Observe C-core's close notification instead.
|
|
8
|
+
# @api private
|
|
9
|
+
module Cancellation
|
|
10
|
+
module ActiveCall
|
|
11
|
+
def cancelled? = @call.gritz_cancelled?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module CoreCall
|
|
15
|
+
def self.extended(call)
|
|
16
|
+
call.instance_variable_set(:@gritz_cancellation_mutex, Mutex.new)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def gritz_cancelled?
|
|
20
|
+
return @gritz_cancelled || false if @gritz_close_observer || @gritz_status_sent || @gritz_closed
|
|
21
|
+
|
|
22
|
+
@gritz_cancellation_mutex.synchronize do
|
|
23
|
+
return @gritz_cancelled || false if @gritz_close_observer || @gritz_status_sent || @gritz_closed
|
|
24
|
+
|
|
25
|
+
@gritz_cancelled ||= false
|
|
26
|
+
@gritz_close_observer = Thread.new do
|
|
27
|
+
method(:run_batch).super_method.call(GRPC::Core::CallOps::RECV_CLOSE_ON_SERVER => nil)
|
|
28
|
+
rescue GRPC::Core::CallError
|
|
29
|
+
nil
|
|
30
|
+
ensure
|
|
31
|
+
# grpc's BatchResult does not expose the C-core cancelled flag.
|
|
32
|
+
# Preserve failed-status cancellation if the observer runs later.
|
|
33
|
+
@gritz_cancelled ||= !@gritz_status_sent
|
|
34
|
+
end
|
|
35
|
+
@gritz_cancelled
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def run_batch(operations)
|
|
40
|
+
# C-core accepts RECV_CLOSE only once. Its observer owns this op;
|
|
41
|
+
# grpc's ordinary status batches retain all their send operations.
|
|
42
|
+
sending_status = operations.key?(GRPC::Core::CallOps::SEND_STATUS_FROM_SERVER)
|
|
43
|
+
receiving_close = operations.key?(GRPC::Core::CallOps::RECV_CLOSE_ON_SERVER)
|
|
44
|
+
if sending_status || receiving_close
|
|
45
|
+
@gritz_cancellation_mutex.synchronize do
|
|
46
|
+
operations = operations.except(GRPC::Core::CallOps::RECV_CLOSE_ON_SERVER) if receiving_close && @gritz_close_observer
|
|
47
|
+
@gritz_status_sent = true if sending_status
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
super
|
|
51
|
+
rescue GRPC::Core::CallError
|
|
52
|
+
@gritz_cancelled = true if sending_status
|
|
53
|
+
raise
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def close
|
|
57
|
+
@gritz_cancellation_mutex.synchronize do
|
|
58
|
+
@gritz_close_observer&.join
|
|
59
|
+
@gritz_closed = true
|
|
60
|
+
super
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def finish_gritz_call
|
|
65
|
+
@gritz_cancellation_mutex.synchronize do
|
|
66
|
+
@gritz_closed = true
|
|
67
|
+
cancel if @gritz_close_observer&.alive?
|
|
68
|
+
end
|
|
69
|
+
close
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class Descriptor < GRPC::RpcDesc
|
|
74
|
+
def run_server_method(active_call, ...)
|
|
75
|
+
raw = active_call.instance_variable_get(:@call)
|
|
76
|
+
raw.extend(CoreCall)
|
|
77
|
+
active_call.extend(ActiveCall)
|
|
78
|
+
super
|
|
79
|
+
ensure
|
|
80
|
+
raw&.finish_gritz_call
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gritz-native
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yudai Takada
|
|
@@ -35,14 +35,14 @@ dependencies:
|
|
|
35
35
|
requirements:
|
|
36
36
|
- - '='
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: 0.9.
|
|
38
|
+
version: 0.9.1
|
|
39
39
|
type: :runtime
|
|
40
40
|
prerelease: false
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
42
|
requirements:
|
|
43
43
|
- - '='
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 0.9.
|
|
45
|
+
version: 0.9.1
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: grpc
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,6 +80,7 @@ files:
|
|
|
80
80
|
- lib/gritz/transport/native.rb
|
|
81
81
|
- lib/gritz/transport/native/bridge.rb
|
|
82
82
|
- lib/gritz/transport/native/call.rb
|
|
83
|
+
- lib/gritz/transport/native/cancellation.rb
|
|
83
84
|
- lib/gritz/transport/native/client.rb
|
|
84
85
|
- lib/gritz/transport/native/client_invocation.rb
|
|
85
86
|
- lib/gritz/transport/native/health.rb
|