Skip to content

Commit

Permalink
Ignore duplicated subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tiram88 committed Oct 27, 2023
1 parent edbcf88 commit 80efa2b
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions rpc/grpc/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
manager::ManagerEvent,
request_handler::handler_factory::HandlerFactory,
};
use kaspa_core::{debug, error, info, trace};
use kaspa_core::{debug, info, trace};
use kaspa_grpc_core::protowire::{KaspadRequest, KaspadResponse};
use kaspa_notify::{
connection::Connection as ConnectionT, error::Error as NotificationError, listener::ListenerId, notifier::Notifier,
Expand Down Expand Up @@ -202,21 +202,17 @@ impl Connection {
}

fn subscribe(&self, core_service: &DynRpcService, rpc_op: RpcApiOps) -> RequestSender {
let (sender, receiver) = mpsc_channel(Self::request_channel_size());
let handler = HandlerFactory::new_handler(rpc_op, self.clone(), core_service, self.inner.notifier.clone(), receiver);
handler.launch();
match self.inner.routing_map.write().entry(rpc_op) {
Entry::Occupied(_) => {
// Overrides an existing route -- panic
error!("GRPC, Connection::subscribe overrides an existing value: {:?}, client: {}", rpc_op, self.identity());
panic!("GRPC, Tried to replace an existing route");
}
Entry::Vacant(entry) => {
let (sender, receiver) = mpsc_channel(Self::request_channel_size());
let handler = HandlerFactory::new_handler(rpc_op, self.clone(), core_service, self.inner.notifier.clone(), receiver);
handler.launch();
entry.insert(sender.clone());
trace!("GRPC, Connection::subscribe - {:?} route is registered, client:{:?}", rpc_op, self.identity());
sender
}
Entry::Occupied(entry) => entry.get().clone(),
}
sender
}

async fn route_to_handler(&self, core_service: &DynRpcService, request: KaspadRequest) -> GrpcServerResult<()> {
Expand Down

0 comments on commit 80efa2b

Please sign in to comment.