Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty TURBO_API causes crash with turbo >=1.11.0 #6921

Closed
1 task done
ihmpavel opened this issue Jan 5, 2024 · 4 comments · Fixed by #6929
Closed
1 task done

Empty TURBO_API causes crash with turbo >=1.11.0 #6921

ihmpavel opened this issue Jan 5, 2024 · 4 comments · Fixed by #6929
Assignees
Labels
kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo

Comments

@ihmpavel
Copy link
Contributor

ihmpavel commented Jan 5, 2024

Verify canary release

  • I verified that the issue exists in the latest Turborepo canary release.

Link to code that reproduces this issue

https://github.com/vercel/turbo/tree/main/examples/with-docker

What package manager are you using / does the bug impact?

Yarn v1

What operating system are you using?

Linux

Which canary version will you have in your reproduction?

1.11.3-canary.2

Describe the Bug

After upgrading Turbo to v1.11.x, building in our Docker image is throwing Panic errors. Check the logs below.

Expected Behavior

Building in Docker should work same in v1.10.x and previous versions.

To Reproduce

Duplicate Docker example, change Node version to v20 and run build.

I have verified, that our issue occurs on any Node version, with turbo >=1.11.0

Contents of `/tmp/report-*.toml` files
name = "turbo"
operating_system = "Alpine Linux 3.19.0 [64-bit]"
crate_version = "1.11.3-canary.2"
explanation = """
file 'crates/turborepo-api-client/src/retry.rs' at line 25
"""
cause = "cannot clone request"
method = "Panic"
backtrace = """

   0:   0xaadba8 - turborepo_api_client::retry::make_retryable_request::{{closure}}::h47dc94bcf701cfc6.30959
   1:   0xa9934c - <turborepo_api_client::APIClient as turborepo_api_client::analytics::AnalyticsClient>::record_analytics::{{closure}}::h3169f58e4c6f1e68
   2:   0xcb77b4 - <tokio::time::timeout::Timeout<T> as core::future::future::Future>::poll::ha440f64b1c1b3321
   3:   0xc73ca0 - turborepo_analytics::Worker<C>::send_events::{{closure}}::hc7b6be12756d5029
   4:   0xd1a734 - tokio::runtime::task::raw::poll::h48e78d40353a2877
   5:   0xa0851c - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h74958dfae80c6dca
   6:   0x9effa0 - tokio::runtime::task::raw::poll::h9d497871a68e1db1
   7:   0x9f9414 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcbc382b24415fb49
   8:   0x9fb32c - core::ops::function::FnOnce::call_once{{vtable.shim}}::hea363e36ad532edd
   9:   0x9bbfcc - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h80e0256344119ecd
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007
                 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hecc439716a31ba3c
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007
                 - std::sys::unix::thread::Thread::new::thread_start::h8e25b89a5e558141
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/unix/thread.rs:108"""

-----

name = "turbo"
operating_system = "Alpine Linux 3.19.0 [64-bit]"
crate_version = "1.11.3-canary.2"
explanation = """
file 'crates/turborepo-api-client/src/retry.rs' at line 25
"""
cause = "cannot clone request"
method = "Panic"
backtrace = """

   0:   0xa9a428 - turborepo_api_client::retry::make_retryable_request::{{closure}}::h47dc94bcf701cfc6
   1:   0xaa6184 - <turborepo_api_client::APIClient as turborepo_api_client::Client>::get_artifact::{{closure}}::h8151163a1b246dfd
   2:   0xaa95e0 - <turborepo_api_client::APIClient as turborepo_api_client::Client>::fetch_artifact::{{closure}}::hf9244dbdb94d966c
   3:   0xdd7ef0 - turborepo_cache::http::HTTPCache::fetch::{{closure}}::{{closure}}::hdadf2c31570c498c
   4:   0xdd743c - turborepo_cache::multiplexer::CacheMultiplexer::fetch::{{closure}}::{{closure}}::h4cd6ddf36b771781
   5:   0xdd6278 - turborepo_cache::async_cache::AsyncCache::fetch::{{closure}}::{{closure}}::h71e49cfe9e686d26
   6:   0xdcd828 - turborepo_lib::run::cache::TaskCache::restore_outputs::{{closure}}::ha0efff305c41a721
   7:   0xdc4844 - turborepo_lib::task_graph::visitor::ExecContext::execute_inner::{{closure}}::h532412df54d16b72
   8:   0xc64530 - turborepo_lib::task_graph::visitor::Visitor::visit::{{closure}}::{{closure}}::{{closure}}::hb77060e45277f330
   9:   0xd17b3c - tokio::runtime::task::raw::poll::h33c454e2b1bea18e
  10:   0xa08444 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h74958dfae80c6dca
  11:   0x9effa0 - tokio::runtime::task::raw::poll::h9d497871a68e1db1
  12:   0x9f9414 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcbc382b24415fb49
  13:   0x9fb32c - core::ops::function::FnOnce::call_once{{vtable.shim}}::hea363e36ad532edd
  14:   0x9bbfcc - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h80e0256344119ecd
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007
                 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hecc439716a31ba3c
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007
                 - std::sys::unix::thread::Thread::new::thread_start::h8e25b89a5e558141
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/unix/thread.rs:108"""
name = "turbo"
operating_system = "Alpine Linux 3.19.0 [64-bit]"
crate_version = "1.11.3-canary.2"
explanation = """
file 'crates/turborepo-lib/src/task_graph/visitor.rs' at line 279
"""
cause = "task executor panicked: JoinError::Panic(Id(34), ...)"
method = "Panic"
backtrace = """

   0:   0xdbfeb0 - turborepo_lib::task_graph::visitor::Visitor::visit::{{closure}}::{{closure}}::h794439fb64e59680
   1:   0xdbd280 - <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll::he016a1478d747664
   2:   0xdafd84 - turborepo_lib::run::Run::run_with_analytics::{{closure}}::h40d9342a1f4ae6ee
   3:   0xfac540 - <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::hfbd829849494b674
   4:   0xd4a08c - turborepo_lib::cli::run::{{closure}}::h208eb4d117f7d867
   5:   0xf7e704 - turborepo_lib::cli::run::hd2a7f7b62b136151
   6:   0xe3d454 - turborepo_lib::shim::run_correct_turbo::hf3da810f5a25dbd6
   7:   0xe399f0 - turborepo_lib::main::hf672299f7af3c6ec
   8:   0xa5dbec - turbo::main::hbfdd7f2162b1bc5a
   9:   0xa774b4 - std::sys_common::backtrace::__rust_begin_short_backtrace::hff9e541e88d9283e
  10:   0xa77138 - std::rt::lang_start::h5a16c1d5119a8613
  11:   0xa5d8c8 - main"""

-----

name = "turbo"
operating_system = "Alpine Linux 3.19.0 [64-bit]"
crate_version = "1.11.3-canary.2"
explanation = """
file 'crates/turborepo-api-client/src/retry.rs' at line 25
"""
cause = "cannot clone request"
method = "Panic"
backtrace = """

   0:   0xa9a428 - turborepo_api_client::retry::make_retryable_request::{{closure}}::h47dc94bcf701cfc6
   1:   0xaa6184 - <turborepo_api_client::APIClient as turborepo_api_client::Client>::get_artifact::{{closure}}::h8151163a1b246dfd
   2:   0xaa95e0 - <turborepo_api_client::APIClient as turborepo_api_client::Client>::fetch_artifact::{{closure}}::hf9244dbdb94d966c
   3:   0xdd7ef0 - turborepo_cache::http::HTTPCache::fetch::{{closure}}::{{closure}}::hdadf2c31570c498c
   4:   0xdd743c - turborepo_cache::multiplexer::CacheMultiplexer::fetch::{{closure}}::{{closure}}::h4cd6ddf36b771781
   5:   0xdd6278 - turborepo_cache::async_cache::AsyncCache::fetch::{{closure}}::{{closure}}::h71e49cfe9e686d26
   6:   0xdcd828 - turborepo_lib::run::cache::TaskCache::restore_outputs::{{closure}}::ha0efff305c41a721
   7:   0xdc4844 - turborepo_lib::task_graph::visitor::ExecContext::execute_inner::{{closure}}::h532412df54d16b72
   8:   0xc64530 - turborepo_lib::task_graph::visitor::Visitor::visit::{{closure}}::{{closure}}::{{closure}}::hb77060e45277f330
   9:   0xd17b3c - tokio::runtime::task::raw::poll::h33c454e2b1bea18e
  10:   0xa08444 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h74958dfae80c6dca
  11:   0x9effa0 - tokio::runtime::task::raw::poll::h9d497871a68e1db1
  12:   0x9f9414 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcbc382b24415fb49
  13:   0x9fb32c - core::ops::function::FnOnce::call_once{{vtable.shim}}::hea363e36ad532edd
  14:   0x9bbfcc - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h80e0256344119ecd
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007
                 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hecc439716a31ba3c
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/alloc/src/boxed.rs:2007
                 - std::sys::unix::thread::Thread::new::thread_start::h8e25b89a5e558141
                at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/sys/unix/thread.rs:108"""

Additional context

Building locally on my M1 Macbook sometime works and sometime throws same error. Nothing has been changed/libraries other than turbo version.

I though, that it is linked with #6715, but still does not work after merging.

@ihmpavel ihmpavel added kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo labels Jan 5, 2024
@chris-olszewski
Copy link
Contributor

I would guess that this stems from Alpine using musl instead of glibc, but it's odd that you have been able to reproduce on your Macbook.

@chris-olszewski
Copy link
Contributor

Are you setting TURBO_API at all or using --api?

@ihmpavel
Copy link
Contributor Author

ihmpavel commented Jan 5, 2024

Hi, thank you for you insights!

I tried building multiple times again, with latest canary release locally on my MacBook outside of Docker, and it looks like it is working again.

In the Dockerfile which is used in the non-working build is:

ARG TURBO_TOKEN
ENV TURBO_TOKEN=$TURBO_TOKEN
ARG TURBO_TEAM
ENV TURBO_TEAM=$TURBO_TEAM
ARG TURBO_API
ENV TURBO_API=$TURBO_API

After deleting the last two lines, the build started working again. The build command is only docker buildx build --file DockerfilePath . without specifying arguments mentioned above (working on 1.10.x fine, but not on 1.11.x).

I tried reading changelog, but I do not see any change regarding TURBO_API variable, but it looks like turbo fails, when an empty TURBO_API variable is present.

I am currently testing this on CI/CD, whether not specifying empty TURBO_API variable/argument in Dockerfile solves the error there.

The ideal way will be the same behavior as in previous minor version. Can you pinpoint me to the source code, where I can find the change? If it will be something trivial, I can try creating PR reverting/fixing this behavior, but I have never worked with Rust before.

@chris-olszewski
Copy link
Contributor

I tried reading changelog, but I do not see any change regarding TURBO_API variable, but it looks like turbo fails, when an empty TURBO_API variable is present.

Thank you so much for this! It looks like we accidentally changed the interpretation of TURBO_API being set but empty so we were trying to make requests to an API url of "". I should have a fix up shortly.

@ihmpavel ihmpavel changed the title Building in Docker fails with Turbo >=1.11.0 Empty TURBO_API causes crash with turbo >=1.11.0 Jan 5, 2024
chris-olszewski added a commit that referenced this issue Jan 6, 2024
### Description

Fixes #6921

Setting `TURBO_API` env var to an empty string results in a panic:
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ TURBO_API= turbo_dev build --filter=docs --output-logs new-only 
• Packages in scope: docs
• Running build in 1 packages
• Remote caching enabled
@turbo/workspaces:build: cache hit (outputs already on disk), suppressing logs 899e29b77bbaa6e9
docs:rss: cache hit (outputs already on disk), suppressing logs 9991721850b37e8a
docs:schema: cache hit (outputs already on disk), suppressing logs 6048fc4f56a96905
@turbo/gen:build: cache hit (outputs already on disk), suppressing logs b8021fbfb2521690
docs:build: cache hit (outputs already on disk), suppressing logs 7f1f00f669ffea14

 Tasks:    5 successful, 5 total
Cached:    5 cached, 5 total
  Time:    495ms >>> FULL TURBO

Oops! Turbo has crashed.

A report has been written to /var/folders/3m/rxkycvgs5jgfvs0k9xcgp6km0000gn/T/report-9ec6c539-2888-430d-9f52-ecd91cf18bc9.toml

Please open an issue at https://github.com/vercel/turbo/issues/new/choose and include this file
 WARNING  failed to close spaces client
```

This is due to us expecting Go-like behavior where the empty string is
the none value. We can achieve this behavior by mapping `Some("")` to
`None`. I think this is a valid change for the various string type
config options as the empty string is never a valid "present" value for
these fields.

### Testing Instructions

Added unit test to verify that we now treat empty set environment
variables as `None`

Quick spot check that this no longer crashes and uses the default API
instead of `""`:
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ TURBO_API= turbo_dev build --filter=docs --output-logs new-only
• Packages in scope: docs
• Running build in 1 packages
• Remote caching enabled
@turbo/workspaces:build: cache hit (outputs already on disk), suppressing logs 899e29b77bbaa6e9
docs:schema: cache hit (outputs already on disk), suppressing logs 6048fc4f56a96905
@turbo/gen:build: cache hit (outputs already on disk), suppressing logs b8021fbfb2521690
docs:rss: cache hit, suppressing logs 9991721850b37e8a
docs:build: cache hit (outputs already on disk), suppressing logs 7f1f00f669ffea14

 Tasks:    5 successful, 5 total
Cached:    5 cached, 5 total
  Time:    502ms >>> FULL TURBO

Run: https://vercel.com/teams/vercel/repos/turbo-monorepo/runs/space_run_EfSNkNZDvtznuFbWhHGfbv1a
```


Closes TURBO-2004
chris-olszewski added a commit that referenced this issue Jan 9, 2024
### Description

As reported in #6921 `turbo` is panicking when making HTTP requests.
This PR doesn't fix the user issue, but it does avoid the panic and
provide a better warning message to the end user.

The panic can be caused in 2 ways:
- Trying to retry a request that has a streaming body. This wasn't
happening, but I changed the code so we at least don't panic if we
accidentally call this function with a streaming body.
- Constructing a `RequestBuilder` with an invalid url (see
seanmonstar/reqwest#1943) will cause the
`try_clone` method to return `None` causing us to panic. This can easily
be done if a user passes an invalid API url. We mitigate this by now
only constructing `RequestBuilder` with `Url` which has already been
verified instead of `&str` which delays the verification and obscures
the failure.

Minor change is removing the `do_preflight` method from the client trait
as it is an implementation detail and it reduced the amount of places
that needed to get updated.

### Testing Instructions

Create a bogus entry in `auth.json` e.g. 
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ bat ~/Library/Application\ Support/turborepo/auth.json 
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /Users/olszewski/Library/Application Support/turborepo/auth.json
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ {
   2   │   "tokens": {
   3   │     "junk-url": "junk-token"
   4   │   }
   5   │ }
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
```

On main verify that the current experience is far from ideal:
<img width="956" alt="Screenshot 2024-01-05 at 1 26 09 PM"
src="https://github.com/vercel/turbo/assets/4131117/f63c60f1-db0f-441f-a386-11e4078cd55c">

Build using these changes and verify that there's a better UX:

<img width="1038" alt="Screenshot 2024-01-05 at 1 30 05 PM"
src="https://github.com/vercel/turbo/assets/4131117/13fb3d21-bf48-44b9-9586-089d03afa8ee">



Closes TURBO-2002
Zertsov pushed a commit that referenced this issue Jan 10, 2024
### Description

Fixes #6921

Setting `TURBO_API` env var to an empty string results in a panic:
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ TURBO_API= turbo_dev build --filter=docs --output-logs new-only 
• Packages in scope: docs
• Running build in 1 packages
• Remote caching enabled
@turbo/workspaces:build: cache hit (outputs already on disk), suppressing logs 899e29b77bbaa6e9
docs:rss: cache hit (outputs already on disk), suppressing logs 9991721850b37e8a
docs:schema: cache hit (outputs already on disk), suppressing logs 6048fc4f56a96905
@turbo/gen:build: cache hit (outputs already on disk), suppressing logs b8021fbfb2521690
docs:build: cache hit (outputs already on disk), suppressing logs 7f1f00f669ffea14

 Tasks:    5 successful, 5 total
Cached:    5 cached, 5 total
  Time:    495ms >>> FULL TURBO

Oops! Turbo has crashed.

A report has been written to /var/folders/3m/rxkycvgs5jgfvs0k9xcgp6km0000gn/T/report-9ec6c539-2888-430d-9f52-ecd91cf18bc9.toml

Please open an issue at https://github.com/vercel/turbo/issues/new/choose and include this file
 WARNING  failed to close spaces client
```

This is due to us expecting Go-like behavior where the empty string is
the none value. We can achieve this behavior by mapping `Some("")` to
`None`. I think this is a valid change for the various string type
config options as the empty string is never a valid "present" value for
these fields.

### Testing Instructions

Added unit test to verify that we now treat empty set environment
variables as `None`

Quick spot check that this no longer crashes and uses the default API
instead of `""`:
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ TURBO_API= turbo_dev build --filter=docs --output-logs new-only
• Packages in scope: docs
• Running build in 1 packages
• Remote caching enabled
@turbo/workspaces:build: cache hit (outputs already on disk), suppressing logs 899e29b77bbaa6e9
docs:schema: cache hit (outputs already on disk), suppressing logs 6048fc4f56a96905
@turbo/gen:build: cache hit (outputs already on disk), suppressing logs b8021fbfb2521690
docs:rss: cache hit, suppressing logs 9991721850b37e8a
docs:build: cache hit (outputs already on disk), suppressing logs 7f1f00f669ffea14

 Tasks:    5 successful, 5 total
Cached:    5 cached, 5 total
  Time:    502ms >>> FULL TURBO

Run: https://vercel.com/teams/vercel/repos/turbo-monorepo/runs/space_run_EfSNkNZDvtznuFbWhHGfbv1a
```


Closes TURBO-2004
Zertsov pushed a commit that referenced this issue Jan 10, 2024
### Description

As reported in #6921 `turbo` is panicking when making HTTP requests.
This PR doesn't fix the user issue, but it does avoid the panic and
provide a better warning message to the end user.

The panic can be caused in 2 ways:
- Trying to retry a request that has a streaming body. This wasn't
happening, but I changed the code so we at least don't panic if we
accidentally call this function with a streaming body.
- Constructing a `RequestBuilder` with an invalid url (see
seanmonstar/reqwest#1943) will cause the
`try_clone` method to return `None` causing us to panic. This can easily
be done if a user passes an invalid API url. We mitigate this by now
only constructing `RequestBuilder` with `Url` which has already been
verified instead of `&str` which delays the verification and obscures
the failure.

Minor change is removing the `do_preflight` method from the client trait
as it is an implementation detail and it reduced the amount of places
that needed to get updated.

### Testing Instructions

Create a bogus entry in `auth.json` e.g. 
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ bat ~/Library/Application\ Support/turborepo/auth.json 
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /Users/olszewski/Library/Application Support/turborepo/auth.json
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ {
   2   │   "tokens": {
   3   │     "junk-url": "junk-token"
   4   │   }
   5   │ }
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
```

On main verify that the current experience is far from ideal:
<img width="956" alt="Screenshot 2024-01-05 at 1 26 09 PM"
src="https://github.com/vercel/turbo/assets/4131117/f63c60f1-db0f-441f-a386-11e4078cd55c">

Build using these changes and verify that there's a better UX:

<img width="1038" alt="Screenshot 2024-01-05 at 1 30 05 PM"
src="https://github.com/vercel/turbo/assets/4131117/13fb3d21-bf48-44b9-9586-089d03afa8ee">



Closes TURBO-2002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants