@@ -381,12 +381,14 @@ impl ReaderDelegate for ServerReader {
381
381
async fn handle_msg ( & self , msg : GenMessage ) {
382
382
let handler_shutdown_waiter = self . handler_shutdown . subscribe ( ) ;
383
383
let context = self . context ( ) ;
384
+ let ( wait_tx, wait_rx) = tokio:: sync:: oneshot:: channel :: < ( ) > ( ) ;
384
385
spawn ( async move {
385
386
select ! {
386
- _ = context. handle_msg( msg) => { }
387
+ _ = context. handle_msg( msg, wait_tx ) => { }
387
388
_ = handler_shutdown_waiter. wait_shutdown( ) => { }
388
389
}
389
390
} ) ;
391
+ wait_rx. await . unwrap_or_default ( ) ;
390
392
}
391
393
392
394
async fn handle_err ( & self , header : MessageHeader , e : Error ) {
@@ -424,7 +426,7 @@ impl HandlerContext {
424
426
} )
425
427
. ok ( ) ;
426
428
}
427
- async fn handle_msg ( & self , msg : GenMessage ) {
429
+ async fn handle_msg ( & self , msg : GenMessage , wait_tx : tokio :: sync :: oneshot :: Sender < ( ) > ) {
428
430
let stream_id = msg. header . stream_id ;
429
431
430
432
if ( stream_id % 2 ) != 1 {
@@ -438,7 +440,7 @@ impl HandlerContext {
438
440
}
439
441
440
442
match msg. header . type_ {
441
- MESSAGE_TYPE_REQUEST => match self . handle_request ( msg) . await {
443
+ MESSAGE_TYPE_REQUEST => match self . handle_request ( msg, wait_tx ) . await {
442
444
Ok ( opt_msg) => match opt_msg {
443
445
Some ( mut resp) => {
444
446
// Server: check size before sending to client
@@ -471,6 +473,8 @@ impl HandlerContext {
471
473
Err ( status) => Self :: respond_with_status ( self . tx . clone ( ) , stream_id, status) . await ,
472
474
} ,
473
475
MESSAGE_TYPE_DATA => {
476
+ // no need to wait data message handling
477
+ drop ( wait_tx) ;
474
478
// TODO(wllenyj): Compatible with golang behavior.
475
479
if ( msg. header . flags & FLAG_REMOTE_CLOSED ) == FLAG_REMOTE_CLOSED
476
480
&& !msg. payload . is_empty ( )
@@ -518,7 +522,11 @@ impl HandlerContext {
518
522
}
519
523
}
520
524
521
- async fn handle_request ( & self , msg : GenMessage ) -> StdResult < Option < Response > , Status > {
525
+ async fn handle_request (
526
+ & self ,
527
+ msg : GenMessage ,
528
+ wait_tx : tokio:: sync:: oneshot:: Sender < ( ) > ,
529
+ ) -> StdResult < Option < Response > , Status > {
522
530
//TODO:
523
531
//if header.stream_id <= self.last_stream_id {
524
532
// return Err;
@@ -539,10 +547,11 @@ impl HandlerContext {
539
547
} ) ?;
540
548
541
549
if let Some ( method) = srv. get_method ( & req. method ) {
550
+ drop ( wait_tx) ;
542
551
return self . handle_method ( method, req_msg) . await ;
543
552
}
544
553
if let Some ( stream) = srv. get_stream ( & req. method ) {
545
- return self . handle_stream ( stream, req_msg) . await ;
554
+ return self . handle_stream ( stream, req_msg, wait_tx ) . await ;
546
555
}
547
556
Err ( get_status (
548
557
Code :: UNIMPLEMENTED ,
@@ -598,6 +607,7 @@ impl HandlerContext {
598
607
& self ,
599
608
stream : Arc < dyn StreamHandler + Send + Sync > ,
600
609
req_msg : Message < Request > ,
610
+ wait_tx : tokio:: sync:: oneshot:: Sender < ( ) > ,
601
611
) -> StdResult < Option < Response > , Status > {
602
612
let stream_id = req_msg. header . stream_id ;
603
613
let req = req_msg. payload ;
@@ -609,6 +619,8 @@ impl HandlerContext {
609
619
610
620
let no_data = ( req_msg. header . flags & FLAG_NO_DATA ) == FLAG_NO_DATA ;
611
621
622
+ drop ( wait_tx) ;
623
+
612
624
let si = StreamInner :: new (
613
625
stream_id,
614
626
self . tx . clone ( ) ,
0 commit comments