Skip to content

Commit

Permalink
improve node.js receive timeout (vercel/turborepo#4584)
Browse files Browse the repository at this point in the history
### Description

move the timeout to the recv call, leaving infinite time for source map
handling of the stdout. That might take longer to compile source maps.
increase the timeout to 60s
  • Loading branch information
sokra authored Apr 14, 2023
1 parent c57b89c commit aabb121
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/turbopack-node/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,22 @@ impl NodeJsPoolProcess {
impl RunningNodeJsPoolProcess {
async fn recv(&mut self) -> Result<Vec<u8>> {
let connection = &mut self.connection;
async fn with_timeout<T, E: Into<anyhow::Error>>(
future: impl Future<Output = Result<T, E>> + Send,
) -> Result<T> {
timeout(Duration::from_secs(60), future)
.await
.context("timeout while receiving message from process")?
.map_err(Into::into)
}
let recv_future = async move {
let packet_len = connection
.read_u32()
let packet_len = with_timeout(connection.read_u32())
.await
.context("reading packet length")?
.try_into()
.context("storing packet length")?;
let mut packet_data = vec![0; packet_len];
connection
.read_exact(&mut packet_data)
with_timeout(connection.read_exact(&mut packet_data))
.await
.context("reading packet data")?;
Ok::<_, anyhow::Error>(packet_data)
Expand Down Expand Up @@ -651,10 +657,7 @@ impl NodeJsOperation {
{
let message = self
.with_process(|process| async move {
timeout(Duration::from_secs(30), process.recv())
.await
.context("timeout while receiving message from process")?
.context("failed to receive message")
process.recv().await.context("failed to receive message")
})
.await?;
serde_json::from_slice(&message).context("failed to deserialize message")
Expand Down

0 comments on commit aabb121

Please sign in to comment.