@@ -53,7 +53,7 @@ use anyhow::bail;
5353use crossbeam_utils:: atomic:: AtomicCell ;
5454use futures_util:: { StreamExt , stream} ;
5555use gethostname:: gethostname;
56- use parking_lot:: { Mutex , RwLock } ;
56+ use parking_lot:: RwLock ;
5757use slot_provider:: SlotProvider ;
5858use std:: {
5959 convert:: TryInto ,
@@ -137,7 +137,7 @@ pub struct Worker {
137137 /// Used to track worker client
138138 client_worker_registrator : Arc < ClientWorkerRegistrator > ,
139139 /// Status of the worker
140- status : Arc < Mutex < WorkerStatus > > ,
140+ status : Arc < RwLock < WorkerStatus > > ,
141141}
142142
143143struct AllPermitsTracker {
@@ -256,7 +256,7 @@ impl WorkerTrait for Worker {
256256 }
257257 self . shutdown_token . cancel ( ) ;
258258 {
259- * self . status . lock ( ) = WorkerStatus :: ShuttingDown ;
259+ * self . status . write ( ) = WorkerStatus :: ShuttingDown ;
260260 }
261261 // First, unregister worker from the client
262262 if !self . client_worker_registrator . shared_namespace_worker {
@@ -276,12 +276,11 @@ impl WorkerTrait for Worker {
276276
277277 if !self . workflows . ever_polled ( ) {
278278 self . local_act_mgr . workflows_have_shutdown ( ) ;
279- } else {
280- // Bump the workflow stream with a pointless input, since if a client initiates shutdown
281- // and then immediately blocks waiting on a workflow activation poll, it's possible that
282- // there may not be any more inputs ever, and that poll will never resolve.
283- self . workflows . send_get_state_info_msg ( ) ;
284279 }
280+ // Bump the workflow stream with a pointless input, since if a client initiates shutdown
281+ // and then immediately blocks waiting on a workflow activation poll, it's possible that
282+ // there may not be any more inputs ever, and that poll will never resolve.
283+ self . workflows . send_get_state_info_msg ( ) ;
285284 }
286285
287286 async fn shutdown ( & self ) {
@@ -361,7 +360,12 @@ impl Worker {
361360
362361 #[ cfg( test) ]
363362 pub ( crate ) fn new_test ( config : WorkerConfig , client : impl WorkerClient + ' static ) -> Self {
364- Self :: new ( config, None , Arc :: new ( client) , None , None ) . unwrap ( )
363+ let sticky_queue_name = if config. max_cached_workflows > 0 {
364+ Some ( format ! ( "sticky-{}" , config. task_queue) )
365+ } else {
366+ None
367+ } ;
368+ Self :: new ( config, sticky_queue_name, Arc :: new ( client) , None , None ) . unwrap ( )
365369 }
366370
367371 pub ( crate ) fn new_with_pollers (
@@ -575,7 +579,7 @@ impl Worker {
575579 deployment_options,
576580 ) ;
577581 let worker_instance_key = Uuid :: new_v4 ( ) ;
578- let worker_status = Arc :: new ( Mutex :: new ( WorkerStatus :: Running ) ) ;
582+ let worker_status = Arc :: new ( RwLock :: new ( WorkerStatus :: Running ) ) ;
579583
580584 let sdk_name_and_ver = client. sdk_name_and_version ( ) ;
581585 let worker_heartbeat = worker_heartbeat_interval. map ( |hb_interval| {
@@ -698,7 +702,10 @@ impl Worker {
698702 tonic:: Code :: Unimplemented | tonic:: Code :: Unavailable
699703 ) =>
700704 {
701- warn ! ( "Failed to shutdown sticky queue {:?}" , err) ;
705+ warn ! (
706+ "shutdown_worker rpc errored during worker shutdown: {:?}" ,
707+ err
708+ ) ;
702709 }
703710 _ => { }
704711 }
@@ -1048,7 +1055,7 @@ struct HeartbeatMetrics {
10481055 wf_sticky_last_suc_poll_time : Arc < AtomicCell < Option < SystemTime > > > ,
10491056 act_last_suc_poll_time : Arc < AtomicCell < Option < SystemTime > > > ,
10501057 nexus_last_suc_poll_time : Arc < AtomicCell < Option < SystemTime > > > ,
1051- status : Arc < Mutex < WorkerStatus > > ,
1058+ status : Arc < RwLock < WorkerStatus > > ,
10521059 sys_info : Arc < dyn SystemResourceInfo + Send + Sync > ,
10531060}
10541061
@@ -1094,7 +1101,7 @@ impl WorkerHeartbeatManager {
10941101 task_queue : config. task_queue . clone ( ) ,
10951102 deployment_version,
10961103
1097- status : ( * heartbeat_manager_metrics. status . lock ( ) ) as i32 ,
1104+ status : ( * heartbeat_manager_metrics. status . read ( ) ) as i32 ,
10981105 start_time,
10991106 plugins : config. plugins . clone ( ) ,
11001107
0 commit comments