|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 |
|
16 | | -require "google/cloud/debugger/async_actor" |
17 | 16 | require "google/cloud/debugger/breakpoint_manager" |
18 | 17 | require "google/cloud/debugger/debuggee" |
19 | 18 | require "google/cloud/debugger/debugger_c" |
20 | 19 | require "google/cloud/debugger/tracer" |
21 | 20 | require "google/cloud/debugger/transmitter" |
22 | 21 | require "google/cloud/logging" |
| 22 | +require "stackdriver/core/async_actor" |
23 | 23 |
|
24 | 24 | module Google |
25 | 25 | module Cloud |
@@ -53,7 +53,7 @@ class Agent |
53 | 53 |
|
54 | 54 | ## |
55 | 55 | # @private Debugger Agent is an asynchronous actor |
56 | | - include AsyncActor |
| 56 | + include Stackdriver::Core::AsyncActor |
57 | 57 |
|
58 | 58 | ## |
59 | 59 | # @private The gRPC Service object. |
@@ -120,6 +120,9 @@ def initialize service, logger: nil, module_name:, module_version: |
120 | 120 | @transmitter = Transmitter.new self, service |
121 | 121 |
|
122 | 122 | @logger = logger || default_logger |
| 123 | + |
| 124 | + # Agent actor thread needs to force exit immediately. |
| 125 | + set_cleanup_options timeout: 0 |
123 | 126 | end |
124 | 127 |
|
125 | 128 | ## |
@@ -167,6 +170,13 @@ def run_backgrounder |
167 | 170 | @last_exception = e |
168 | 171 | end |
169 | 172 |
|
| 173 | + ## |
| 174 | + # @private Callback function to be invoked when the agent actor is about |
| 175 | + # to be stopped. |
| 176 | + def cleanup_callback |
| 177 | + tracer.stop |
| 178 | + end |
| 179 | + |
170 | 180 | private |
171 | 181 |
|
172 | 182 | ## |
@@ -197,19 +207,10 @@ def ensure_debuggee_registration |
197 | 207 | end |
198 | 208 |
|
199 | 209 | ## |
200 | | - # @private Override AsyncActor#async_stop to immediately kill the child |
201 | | - # thread instead of waiting for it to return, because the breakpoints |
202 | | - # are queried with a hanging long poll mechanism. |
203 | | - def async_stop |
204 | | - @startup_lock.synchronize do |
205 | | - unless @thread.nil? |
206 | | - tracer.stop |
207 | | - |
208 | | - @async_state = :stopped |
209 | | - @thread.kill |
210 | | - @thread.join |
211 | | - end |
212 | | - end |
| 210 | + # @private Override the #backgrounder_stoppable? method from AsyncActor |
| 211 | + # module. The actor can be stopped unconditionally. |
| 212 | + def backgrounder_stoppable? |
| 213 | + true |
213 | 214 | end |
214 | 215 |
|
215 | 216 | ## |
|
0 commit comments