@@ -412,7 +412,11 @@ impl NetworkHandler {
412
412
Status :: Subscribed => {
413
413
if let Some ( resp_buf) = self . try_match_pubsub_message ( result) . await {
414
414
self . receive_result ( resp_buf) ;
415
- if self . subscriptions . is_empty ( ) {
415
+ if self . subscriptions . is_empty ( ) && self . pending_subscriptions . is_empty ( ) {
416
+ debug ! (
417
+ "[{}] goint out from Pub/Sub state to connected state" ,
418
+ self . tag
419
+ ) ;
416
420
self . status = Status :: Connected ;
417
421
}
418
422
}
@@ -591,24 +595,36 @@ impl NetworkHandler {
591
595
| RefPubSubMessage :: SSubscribe ( channel_or_pattern) => {
592
596
if let Some ( pending_sub) = self . pending_subscriptions . pop_front ( ) {
593
597
if pending_sub. channel_or_pattern == channel_or_pattern {
594
- self . subscriptions . insert (
595
- channel_or_pattern. to_vec ( ) ,
596
- ( pending_sub. subscription_type , pending_sub. sender ) ,
597
- ) ;
598
+ if self
599
+ . subscriptions
600
+ . insert (
601
+ channel_or_pattern. to_vec ( ) ,
602
+ ( pending_sub. subscription_type , pending_sub. sender ) ,
603
+ )
604
+ . is_some ( )
605
+ {
606
+ return Some ( Err ( Error :: Client (
607
+ format ! (
608
+ "There is already a subscription on channel '{}'" ,
609
+ String :: from_utf8_lossy( channel_or_pattern)
610
+ )
611
+ . to_string ( ) ,
612
+ ) ) ) ;
613
+ }
598
614
599
615
if pending_sub. more_to_come {
600
616
return None ;
601
617
}
602
618
} else {
603
619
error ! (
604
- "[{}] Unexpected subscription confirmation on channel '{:? }'" ,
620
+ "[{}] Unexpected subscription confirmation on channel '{}'" ,
605
621
self . tag,
606
622
String :: from_utf8_lossy( channel_or_pattern)
607
623
) ;
608
624
}
609
625
} else {
610
626
error ! (
611
- "[{}] Cannot find pending subscription for channel '{:? }'" ,
627
+ "[{}] Cannot find pending subscription for channel '{}'" ,
612
628
self . tag,
613
629
String :: from_utf8_lossy( channel_or_pattern)
614
630
) ;
@@ -666,7 +682,7 @@ impl NetworkHandler {
666
682
}
667
683
None => {
668
684
error ! (
669
- "[{}] Unexpected message on channel '{:? }' for pattern '{:? }'" ,
685
+ "[{}] Unexpected message on channel '{}' for pattern '{}'" ,
670
686
self . tag,
671
687
String :: from_utf8_lossy( channel) ,
672
688
String :: from_utf8_lossy( pattern)
0 commit comments