diff --git a/substrate/core/network-libp2p/src/custom_proto/upgrade.rs b/substrate/core/network-libp2p/src/custom_proto/upgrade.rs index 4bc52c2130..992989b3f3 100644 --- a/substrate/core/network-libp2p/src/custom_proto/upgrade.rs +++ b/substrate/core/network-libp2p/src/custom_proto/upgrade.rs @@ -103,10 +103,15 @@ impl RegisteredProtocolSubstream { /// After calling this, the stream is guaranteed to finish soon-ish. pub fn shutdown(&mut self) { self.is_closing = true; + self.send_queue.clear(); } /// Sends a message to the substream. pub fn send_message(&mut self, data: Bytes) { + if self.is_closing { + return + } + self.send_queue.push_back(data); // If the length of the queue goes over a certain arbitrary threshold, we print a warning.