mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 18:46:49 +00:00
Avoid holding project handle on a call that could hang
This fixes a leaked handle error.
This commit is contained in:
parent
77e322cb75
commit
4256a96051
1 changed files with 9 additions and 2 deletions
|
@ -4185,8 +4185,11 @@ impl Project {
|
||||||
} else if let Some(project_id) = self.remote_id() {
|
} else if let Some(project_id) = self.remote_id() {
|
||||||
let rpc = self.client.clone();
|
let rpc = self.client.clone();
|
||||||
let message = request.to_proto(project_id, buffer);
|
let message = request.to_proto(project_id, buffer);
|
||||||
return cx.spawn(|this, cx| async move {
|
return cx.spawn_weak(|this, cx| async move {
|
||||||
let response = rpc.request(message).await?;
|
let response = rpc.request(message).await?;
|
||||||
|
let this = this
|
||||||
|
.upgrade(&cx)
|
||||||
|
.ok_or_else(|| anyhow!("project dropped"))?;
|
||||||
if this.read_with(&cx, |this, _| this.is_read_only()) {
|
if this.read_with(&cx, |this, _| this.is_read_only()) {
|
||||||
Err(anyhow!("disconnected before completing request"))
|
Err(anyhow!("disconnected before completing request"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -5720,8 +5723,11 @@ impl Project {
|
||||||
) -> Task<Result<ModelHandle<Buffer>>> {
|
) -> Task<Result<ModelHandle<Buffer>>> {
|
||||||
let mut opened_buffer_rx = self.opened_buffer.1.clone();
|
let mut opened_buffer_rx = self.opened_buffer.1.clone();
|
||||||
|
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn_weak(|this, mut cx| async move {
|
||||||
let buffer = loop {
|
let buffer = loop {
|
||||||
|
let Some(this) = this.upgrade(&cx) else {
|
||||||
|
return Err(anyhow!("project dropped"));
|
||||||
|
};
|
||||||
let buffer = this.read_with(&cx, |this, cx| {
|
let buffer = this.read_with(&cx, |this, cx| {
|
||||||
this.opened_buffers
|
this.opened_buffers
|
||||||
.get(&id)
|
.get(&id)
|
||||||
|
@ -5736,6 +5742,7 @@ impl Project {
|
||||||
this.update(&mut cx, |this, _| {
|
this.update(&mut cx, |this, _| {
|
||||||
this.incomplete_remote_buffers.entry(id).or_default();
|
this.incomplete_remote_buffers.entry(id).or_default();
|
||||||
});
|
});
|
||||||
|
drop(this);
|
||||||
opened_buffer_rx
|
opened_buffer_rx
|
||||||
.next()
|
.next()
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue