ssh remote: Only send a single FlushBufferedMessages (#19541)
Release Notes: - N/A --------- Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
parent
27d1a566d0
commit
a367c6de6e
1 changed files with 28 additions and 6 deletions
|
@ -1613,9 +1613,18 @@ impl ChannelClient {
|
||||||
pub fn request<T: RequestMessage>(
|
pub fn request<T: RequestMessage>(
|
||||||
&self,
|
&self,
|
||||||
payload: T,
|
payload: T,
|
||||||
|
) -> impl 'static + Future<Output = Result<T::Response>> {
|
||||||
|
self.request_internal(payload, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_internal<T: RequestMessage>(
|
||||||
|
&self,
|
||||||
|
payload: T,
|
||||||
|
use_buffer: bool,
|
||||||
) -> impl 'static + Future<Output = Result<T::Response>> {
|
) -> impl 'static + Future<Output = Result<T::Response>> {
|
||||||
log::debug!("ssh request start. name:{}", T::NAME);
|
log::debug!("ssh request start. name:{}", T::NAME);
|
||||||
let response = self.request_dynamic(payload.into_envelope(0, None, None), T::NAME);
|
let response =
|
||||||
|
self.request_dynamic(payload.into_envelope(0, None, None), T::NAME, use_buffer);
|
||||||
async move {
|
async move {
|
||||||
let response = response.await?;
|
let response = response.await?;
|
||||||
log::debug!("ssh request finish. name:{}", T::NAME);
|
log::debug!("ssh request finish. name:{}", T::NAME);
|
||||||
|
@ -1627,7 +1636,9 @@ impl ChannelClient {
|
||||||
pub async fn resync(&self, timeout: Duration) -> Result<()> {
|
pub async fn resync(&self, timeout: Duration) -> Result<()> {
|
||||||
smol::future::or(
|
smol::future::or(
|
||||||
async {
|
async {
|
||||||
self.request(proto::FlushBufferedMessages {}).await?;
|
self.request_internal(proto::FlushBufferedMessages {}, false)
|
||||||
|
.await?;
|
||||||
|
|
||||||
for envelope in self.buffer.lock().iter() {
|
for envelope in self.buffer.lock().iter() {
|
||||||
self.outgoing_tx
|
self.outgoing_tx
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -1663,10 +1674,11 @@ impl ChannelClient {
|
||||||
self.send_dynamic(payload.into_envelope(0, None, None))
|
self.send_dynamic(payload.into_envelope(0, None, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_dynamic(
|
fn request_dynamic(
|
||||||
&self,
|
&self,
|
||||||
mut envelope: proto::Envelope,
|
mut envelope: proto::Envelope,
|
||||||
type_name: &'static str,
|
type_name: &'static str,
|
||||||
|
use_buffer: bool,
|
||||||
) -> impl 'static + Future<Output = Result<proto::Envelope>> {
|
) -> impl 'static + Future<Output = Result<proto::Envelope>> {
|
||||||
envelope.id = self.next_message_id.fetch_add(1, SeqCst);
|
envelope.id = self.next_message_id.fetch_add(1, SeqCst);
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
@ -1674,7 +1686,11 @@ impl ChannelClient {
|
||||||
response_channels_lock.insert(MessageId(envelope.id), tx);
|
response_channels_lock.insert(MessageId(envelope.id), tx);
|
||||||
drop(response_channels_lock);
|
drop(response_channels_lock);
|
||||||
|
|
||||||
let result = self.send_buffered(envelope);
|
let result = if use_buffer {
|
||||||
|
self.send_buffered(envelope)
|
||||||
|
} else {
|
||||||
|
self.send_unbuffered(envelope)
|
||||||
|
};
|
||||||
async move {
|
async move {
|
||||||
if let Err(error) = &result {
|
if let Err(error) = &result {
|
||||||
log::error!("failed to send message: {}", error);
|
log::error!("failed to send message: {}", error);
|
||||||
|
@ -1694,7 +1710,7 @@ impl ChannelClient {
|
||||||
self.send_buffered(envelope)
|
self.send_buffered(envelope)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_buffered(&self, mut envelope: proto::Envelope) -> Result<()> {
|
fn send_buffered(&self, mut envelope: proto::Envelope) -> Result<()> {
|
||||||
envelope.ack_id = Some(self.max_received.load(SeqCst));
|
envelope.ack_id = Some(self.max_received.load(SeqCst));
|
||||||
self.buffer.lock().push_back(envelope.clone());
|
self.buffer.lock().push_back(envelope.clone());
|
||||||
// ignore errors on send (happen while we're reconnecting)
|
// ignore errors on send (happen while we're reconnecting)
|
||||||
|
@ -1702,6 +1718,12 @@ impl ChannelClient {
|
||||||
self.outgoing_tx.lock().unbounded_send(envelope).ok();
|
self.outgoing_tx.lock().unbounded_send(envelope).ok();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn send_unbuffered(&self, mut envelope: proto::Envelope) -> Result<()> {
|
||||||
|
envelope.ack_id = Some(self.max_received.load(SeqCst));
|
||||||
|
self.outgoing_tx.lock().unbounded_send(envelope).ok();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProtoClient for ChannelClient {
|
impl ProtoClient for ChannelClient {
|
||||||
|
@ -1710,7 +1732,7 @@ impl ProtoClient for ChannelClient {
|
||||||
envelope: proto::Envelope,
|
envelope: proto::Envelope,
|
||||||
request_type: &'static str,
|
request_type: &'static str,
|
||||||
) -> BoxFuture<'static, Result<proto::Envelope>> {
|
) -> BoxFuture<'static, Result<proto::Envelope>> {
|
||||||
self.request_dynamic(envelope, request_type).boxed()
|
self.request_dynamic(envelope, request_type, true).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&self, envelope: proto::Envelope, _message_type: &'static str) -> Result<()> {
|
fn send(&self, envelope: proto::Envelope, _message_type: &'static str) -> Result<()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue