@@ -18,7 +18,7 @@ use futures::{Stream, StreamExt};
18
18
use tokio:: io:: { AsyncRead , AsyncWrite , ReadBuf } ;
19
19
use tokio:: sync:: oneshot;
20
20
use tokio:: try_join;
21
- use tracing:: { instrument, trace, warn} ;
21
+ use tracing:: { debug , instrument, trace, warn} ;
22
22
use wrpc_transport:: Index as _;
23
23
24
24
pub const PROTOCOL : & str = "wrpc.0.0.1" ;
@@ -314,11 +314,15 @@ pub struct Reader {
314
314
impl wrpc_transport:: Index < Self > for Reader {
315
315
#[ instrument( level = "trace" , skip( self ) ) ]
316
316
fn index ( & self , path : & [ usize ] ) -> anyhow:: Result < Self > {
317
+ trace ! ( "locking index tree" ) ;
317
318
let mut nested = self
318
319
. nested
319
320
. lock ( )
320
321
. map_err ( |err| anyhow ! ( err. to_string( ) ) . context ( "failed to lock map" ) ) ?;
321
- let incoming = nested. take ( path) . context ( "unknown subscription" ) ?;
322
+ trace ! ( "taking index subscription" ) ;
323
+ let incoming = nested
324
+ . take ( path)
325
+ . with_context ( || format ! ( "unknown subscription for path `{path:?}`" ) ) ?;
322
326
Ok ( Self {
323
327
buffer : Bytes :: default ( ) ,
324
328
incoming,
@@ -391,7 +395,7 @@ impl SubjectWriter {
391
395
impl wrpc_transport:: Index < Self > for SubjectWriter {
392
396
#[ instrument( level = "trace" , skip( self ) ) ]
393
397
fn index ( & self , path : & [ usize ] ) -> anyhow:: Result < Self > {
394
- let tx: Subject = index_path ( self . tx . as_str ( ) , path) . into ( ) ;
398
+ let tx = Subject :: from ( index_path ( self . tx . as_str ( ) , path) ) ;
395
399
let publisher = self . nats . publish_sink ( tx. clone ( ) ) ;
396
400
Ok ( Self {
397
401
nats : Arc :: clone ( & self . nats ) ,
@@ -402,7 +406,7 @@ impl wrpc_transport::Index<Self> for SubjectWriter {
402
406
}
403
407
404
408
impl AsyncWrite for SubjectWriter {
405
- #[ instrument( level = "trace" , skip_all, ret, fields( subject = ? self . tx, buf = format!( "{buf:02x?}" ) ) ) ]
409
+ #[ instrument( level = "trace" , skip_all, ret, fields( subject = self . tx. as_str ( ) , buf = format!( "{buf:02x?}" ) ) ) ]
406
410
fn poll_write (
407
411
mut self : Pin < & mut Self > ,
408
412
cx : & mut Context < ' _ > ,
@@ -436,15 +440,15 @@ impl AsyncWrite for SubjectWriter {
436
440
}
437
441
}
438
442
439
- #[ instrument( level = "trace" , skip_all, ret, fields( subject = ? self . tx) ) ]
443
+ #[ instrument( level = "trace" , skip_all, ret, fields( subject = self . tx. as_str ( ) ) ) ]
440
444
fn poll_flush ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < std:: io:: Result < ( ) > > {
441
445
trace ! ( "flushing" ) ;
442
446
self . publisher
443
447
. poll_flush_unpin ( cx)
444
448
. map_err ( |_| std:: io:: ErrorKind :: BrokenPipe . into ( ) )
445
449
}
446
450
447
- #[ instrument( level = "trace" , skip_all, ret, fields( subject = ? self . tx) ) ]
451
+ #[ instrument( level = "trace" , skip_all, ret, fields( subject = self . tx. as_str ( ) ) ) ]
448
452
fn poll_shutdown ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < std:: io:: Result < ( ) > > {
449
453
trace ! ( "writing empty buffer to shut down stream" ) ;
450
454
ready ! ( self . as_mut( ) . poll_write( cx, & [ ] ) ) ?;
@@ -822,16 +826,17 @@ impl wrpc_transport::Invoke for Client {
822
826
type Incoming = Reader ;
823
827
824
828
#[ instrument( level = "trace" , skip( self , paths, params) , fields( params = format!( "{params:02x?}" ) ) ) ]
825
- async fn invoke (
829
+ async fn invoke < P : AsRef < [ Option < usize > ] > + Send + Sync > (
826
830
& self ,
827
831
cx : Self :: Context ,
828
832
instance : & str ,
829
833
func : & str ,
830
834
mut params : Bytes ,
831
- paths : & [ impl AsRef < [ Option < usize > ] > + Send + Sync ] ,
835
+ paths : impl AsRef < [ P ] > + Send ,
832
836
) -> anyhow:: Result < ( Self :: Outgoing , Self :: Incoming ) > {
833
837
let rx = Subject :: from ( self . nats . new_inbox ( ) ) ;
834
838
let result_rx = Subject :: from ( result_subject ( & rx) ) ;
839
+ let paths = paths. as_ref ( ) ;
835
840
let ( result_rx, handshake_rx, nested) = try_join ! (
836
841
async {
837
842
self . nats
@@ -930,15 +935,20 @@ async fn serve_connection(
930
935
let tx = tx. context ( "peer did not specify a reply subject" ) ?;
931
936
let rx = nats. new_inbox ( ) ;
932
937
let param_rx = Subject :: from ( param_subject ( & rx) ) ;
933
- trace ! ( "subscribing on subjects" ) ;
934
938
let ( param_rx, nested) = try_join ! (
935
939
async {
940
+ trace!(
941
+ subject = param_rx. as_str( ) ,
942
+ "subscribing on parameter subject"
943
+ ) ;
936
944
nats. subscribe( param_rx. clone( ) )
937
945
. await
938
946
. context( "failed to subscribe on parameter subject" )
939
947
} ,
940
948
try_join_all( paths. iter( ) . map( |path| async {
941
- nats. subscribe( Subject :: from( subscribe_path( & param_rx, path. as_ref( ) ) ) )
949
+ let subject = subscribe_path( & param_rx, path. as_ref( ) ) ;
950
+ trace!( ?subject, "subscribing on nested parameter subject" ) ;
951
+ nats. subscribe( Subject :: from( subject) )
942
952
. await
943
953
. context( "failed to subscribe on nested parameter subject" )
944
954
} ) )
@@ -974,20 +984,22 @@ impl wrpc_transport::Serve for Client {
974
984
type Incoming = Reader ;
975
985
976
986
#[ instrument( level = "trace" , skip( self , paths) ) ]
977
- async fn serve < P : AsRef < [ Option < usize > ] > + Send + Sync + ' static > (
987
+ async fn serve (
978
988
& self ,
979
989
instance : & str ,
980
990
func : & str ,
981
- paths : impl Into < Arc < [ P ] > > + Send + Sync + ' static ,
991
+ paths : impl Into < Arc < [ Box < [ Option < usize > ] > ] > > + Send ,
982
992
) -> anyhow:: Result <
983
993
impl Stream < Item = anyhow:: Result < ( Self :: Context , Self :: Outgoing , Self :: Incoming ) > > + ' static ,
984
994
> {
985
995
let subject = invocation_subject ( & self . prefix , instance, func) ;
986
996
let sub = if let Some ( group) = & self . queue_group {
997
+ debug ! ( subject, ?group, "queue-subscribing on invocation subject" ) ;
987
998
self . nats
988
999
. queue_subscribe ( subject, group. to_string ( ) )
989
1000
. await ?
990
1001
} else {
1002
+ debug ! ( subject, "subscribing on invocation subject" ) ;
991
1003
self . nats . subscribe ( subject) . await ?
992
1004
} ;
993
1005
let paths = paths. into ( ) ;
0 commit comments