@@ -22,14 +22,21 @@ use std::collections::HashMap;
22
22
use std:: sync:: { Arc , Weak } ;
23
23
use std:: time:: Duration ;
24
24
use tokio_util:: sync:: CancellationToken ;
25
+ use zenoh_buffers:: ZBuf ;
25
26
use zenoh_config:: WhatAmI ;
26
27
use zenoh_protocol:: core:: key_expr:: keyexpr;
28
+ use zenoh_protocol:: core:: KnownEncoding ;
27
29
use zenoh_protocol:: network:: declare:: queryable:: ext:: QueryableInfo ;
30
+ use zenoh_protocol:: zenoh;
31
+ use zenoh_protocol:: zenoh:: ext:: ValueType ;
28
32
use zenoh_protocol:: {
29
33
core:: { Encoding , WireExpr } ,
30
34
network:: {
31
35
declare:: ext,
32
- request:: { ext:: TargetType , Request , RequestId } ,
36
+ request:: {
37
+ ext:: { BudgetType , TargetType , TimeoutType } ,
38
+ Request , RequestId ,
39
+ } ,
33
40
response:: { self , ext:: ResponderIdType , Response , ResponseFinal } ,
34
41
} ,
35
42
zenoh:: { reply:: ext:: ConsolidationType , Reply , RequestBody , ResponseBody } ,
@@ -365,6 +372,7 @@ struct QueryCleanup {
365
372
tables : Arc < TablesLock > ,
366
373
face : Weak < FaceState > ,
367
374
qid : RequestId ,
375
+ timeout : Duration ,
368
376
}
369
377
370
378
impl QueryCleanup {
@@ -378,6 +386,7 @@ impl QueryCleanup {
378
386
tables : tables_ref. clone ( ) ,
379
387
face : Arc :: downgrade ( face) ,
380
388
qid,
389
+ timeout,
381
390
} ;
382
391
if let Some ( ( _, cancellation_token) ) = face. pending_queries . get ( & qid) {
383
392
let c_cancellation_token = cancellation_token. clone ( ) ;
@@ -396,17 +405,42 @@ impl QueryCleanup {
396
405
impl Timed for QueryCleanup {
397
406
async fn run ( & mut self ) {
398
407
if let Some ( mut face) = self . face . upgrade ( ) {
399
- let tables_lock = zwrite ! ( self . tables. tables) ;
408
+ let ext_respid = Some ( response:: ext:: ResponderIdType {
409
+ zid : face. zid ,
410
+ eid : 0 ,
411
+ } ) ;
412
+ route_send_response (
413
+ & self . tables ,
414
+ & mut face,
415
+ self . qid ,
416
+ ext_respid,
417
+ WireExpr :: empty ( ) ,
418
+ ResponseBody :: Err ( zenoh:: Err {
419
+ timestamp : None ,
420
+ is_infrastructure : false ,
421
+ ext_sinfo : None ,
422
+ ext_unknown : vec ! [ ] ,
423
+ ext_body : Some ( ValueType {
424
+ #[ cfg( feature = "shared-memory" ) ]
425
+ ext_shm : None ,
426
+ payload : ZBuf :: from ( "Timeout" . as_bytes ( ) . to_vec ( ) ) ,
427
+ encoding : KnownEncoding :: TextPlain . into ( ) ,
428
+ } ) ,
429
+ code : 0 , // TODO
430
+ } ) ,
431
+ ) ;
432
+ let queries_lock = zwrite ! ( self . tables. queries_lock) ;
400
433
if let Some ( query) = get_mut_unchecked ( & mut face)
401
434
. pending_queries
402
435
. remove ( & self . qid )
403
436
{
404
- drop ( tables_lock ) ;
437
+ drop ( queries_lock ) ;
405
438
tracing:: warn!(
406
- "Didn't receive final reply {}:{} from {}: Timeout!" ,
439
+ "Didn't receive final reply {}:{} from {}: Timeout({:#?}) !" ,
407
440
query. 0 . src_face,
408
441
self . qid,
409
- face
442
+ face,
443
+ self . timeout,
410
444
) ;
411
445
finalize_pending_query ( query) ;
412
446
}
@@ -513,12 +547,15 @@ macro_rules! inc_res_stats {
513
547
} ;
514
548
}
515
549
550
+ #[ allow( clippy:: too_many_arguments) ]
516
551
pub fn route_query (
517
552
tables_ref : & Arc < TablesLock > ,
518
553
face : & Arc < FaceState > ,
519
554
expr : & WireExpr ,
520
555
qid : RequestId ,
521
- target : TargetType ,
556
+ ext_target : TargetType ,
557
+ ext_budget : Option < BudgetType > ,
558
+ ext_timeout : Option < TimeoutType > ,
522
559
body : RequestBody ,
523
560
routing_context : NodeId ,
524
561
) {
@@ -555,14 +592,15 @@ pub fn route_query(
555
592
} ) ;
556
593
557
594
let queries_lock = zwrite ! ( tables_ref. queries_lock) ;
558
- let route = compute_final_route ( & rtables, & route, face, & mut expr, & target, query) ;
595
+ let route =
596
+ compute_final_route ( & rtables, & route, face, & mut expr, & ext_target, query) ;
559
597
let local_replies =
560
598
rtables
561
599
. hat_code
562
600
. compute_local_replies ( & rtables, & prefix, expr. suffix , face) ;
563
601
let zid = rtables. zid ;
564
602
565
- let timeout = rtables. queries_default_timeout ;
603
+ let timeout = ext_timeout . unwrap_or ( rtables. queries_default_timeout ) ;
566
604
567
605
drop ( queries_lock) ;
568
606
drop ( rtables) ;
@@ -643,8 +681,8 @@ pub fn route_query(
643
681
ext_tstamp : None ,
644
682
ext_nodeid : ext:: NodeIdType { node_id : * context } ,
645
683
ext_target : * t,
646
- ext_budget : None ,
647
- ext_timeout : None ,
684
+ ext_budget,
685
+ ext_timeout,
648
686
payload : body. clone ( ) ,
649
687
} ,
650
688
expr. full_expr ( ) . to_string ( ) ,
@@ -673,9 +711,9 @@ pub fn route_query(
673
711
ext_qos : ext:: QoSType :: request_default ( ) ,
674
712
ext_tstamp : None ,
675
713
ext_nodeid : ext:: NodeIdType { node_id : * context } ,
676
- ext_target : target ,
677
- ext_budget : None ,
678
- ext_timeout : None ,
714
+ ext_target,
715
+ ext_budget,
716
+ ext_timeout,
679
717
payload : body. clone ( ) ,
680
718
} ,
681
719
expr. full_expr ( ) . to_string ( ) ,
0 commit comments