diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-04 19:12:49 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-04 19:12:49 +0000 |
commit | 571f247fbc48de8fcdda278242efb27c118193b2 (patch) | |
tree | 2ad6199ec82c009112e16af93b32bc7e3a2b0b46 /crates/proc_macro_api | |
parent | 2756abb167ca31ce206584dc6dc3463338625a3a (diff) | |
parent | 869ad13cf173e65e6c54896743974ac977f5674b (diff) |
Merge #6725
6725: Don't respawn proc macro server on crash r=jonas-schievink a=jonas-schievink
Now the thread managing IPC will exit when the server process crashes instead of respawning it.
Closes https://github.com/rust-analyzer/rust-analyzer/issues/6707
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/proc_macro_api')
-rw-r--r-- | crates/proc_macro_api/src/process.rs | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index b66613c38..301888a0e 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs | |||
@@ -81,15 +81,16 @@ impl ProcMacroProcessSrv { | |||
81 | { | 81 | { |
82 | let (result_tx, result_rx) = bounded(0); | 82 | let (result_tx, result_rx) = bounded(0); |
83 | let sender = match self.inner.upgrade() { | 83 | let sender = match self.inner.upgrade() { |
84 | None => { | 84 | None => return Err(tt::ExpansionError::Unknown("proc macro process is closed".into())), |
85 | return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into())) | ||
86 | } | ||
87 | Some(it) => it, | 85 | Some(it) => it, |
88 | }; | 86 | }; |
89 | sender.send(Task { req, result_tx }).unwrap(); | 87 | sender |
88 | .send(Task { req, result_tx }) | ||
89 | .map_err(|_| tt::ExpansionError::Unknown("proc macro server crashed".into()))?; | ||
90 | |||
90 | let res = result_rx | 91 | let res = result_rx |
91 | .recv() | 92 | .recv() |
92 | .map_err(|_| tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?; | 93 | .map_err(|_| tt::ExpansionError::Unknown("proc macro server crashed".into()))?; |
93 | 94 | ||
94 | match res { | 95 | match res { |
95 | Some(Response::Error(err)) => { | 96 | Some(Response::Error(err)) => { |
@@ -110,21 +111,17 @@ fn client_loop(task_rx: Receiver<Task>, mut process: Process) { | |||
110 | match send_request(&mut stdin, &mut stdout, req) { | 111 | match send_request(&mut stdin, &mut stdout, req) { |
111 | Ok(res) => result_tx.send(res).unwrap(), | 112 | Ok(res) => result_tx.send(res).unwrap(), |
112 | Err(_err) => { | 113 | Err(_err) => { |
114 | log::error!( | ||
115 | "proc macro server crashed, server process state: {:?}", | ||
116 | process.child.try_wait() | ||
117 | ); | ||
113 | let res = Response::Error(ResponseError { | 118 | let res = Response::Error(ResponseError { |
114 | code: ErrorCode::ServerErrorEnd, | 119 | code: ErrorCode::ServerErrorEnd, |
115 | message: "Server closed".into(), | 120 | message: "proc macro server crashed".into(), |
116 | }); | 121 | }); |
117 | result_tx.send(res.into()).unwrap(); | 122 | result_tx.send(res.into()).unwrap(); |
118 | // Restart the process | 123 | // Exit the thread. |
119 | if process.restart().is_err() { | 124 | break; |
120 | break; | ||
121 | } | ||
122 | let stdio = match process.stdio() { | ||
123 | None => break, | ||
124 | Some(it) => it, | ||
125 | }; | ||
126 | stdin = stdio.0; | ||
127 | stdout = stdio.1; | ||
128 | } | 125 | } |
129 | } | 126 | } |
130 | } | 127 | } |
@@ -136,8 +133,6 @@ struct Task { | |||
136 | } | 133 | } |
137 | 134 | ||
138 | struct Process { | 135 | struct Process { |
139 | path: PathBuf, | ||
140 | args: Vec<OsString>, | ||
141 | child: Child, | 136 | child: Child, |
142 | } | 137 | } |
143 | 138 | ||
@@ -152,15 +147,9 @@ impl Process { | |||
152 | path: PathBuf, | 147 | path: PathBuf, |
153 | args: impl IntoIterator<Item = impl AsRef<OsStr>>, | 148 | args: impl IntoIterator<Item = impl AsRef<OsStr>>, |
154 | ) -> io::Result<Process> { | 149 | ) -> io::Result<Process> { |
155 | let args = args.into_iter().map(|s| s.as_ref().into()).collect(); | 150 | let args: Vec<OsString> = args.into_iter().map(|s| s.as_ref().into()).collect(); |
156 | let child = mk_child(&path, &args)?; | 151 | let child = mk_child(&path, &args)?; |
157 | Ok(Process { path, args, child }) | 152 | Ok(Process { child }) |
158 | } | ||
159 | |||
160 | fn restart(&mut self) -> io::Result<()> { | ||
161 | let _ = self.child.kill(); | ||
162 | self.child = mk_child(&self.path, &self.args)?; | ||
163 | Ok(()) | ||
164 | } | 153 | } |
165 | 154 | ||
166 | fn stdio(&mut self) -> Option<(impl Write, impl BufRead)> { | 155 | fn stdio(&mut self) -> Option<(impl Write, impl BufRead)> { |