Trying to setup postgres locally, getting "failed ...
# help
r
I'm pretty new to postgres/docker, so this could be a very silly problem. I followed the docs [here](https://docs.shuttle.rs/introduction/local-run#local-runs-with-databases) and have a main function like:
Copy code
rs
#[shuttle_runtime::main]
async fn rocket(
    #[shuttle_aws_rds::Postgres()]
    pool: PgPool,
) -> shuttle_rocket::ShuttleRocket {
    pool.execute(include_str!("../schema.sql"))
        .await
        .map_err(CustomError::new)?;

    let state = MyState { pool: pool };
    let rocket = rocket::build()
        .mount("/v1.0", routes![outages, _area_search])
        .mount("/esp/2.0", routes![esp_index, esp_status])
        .manage(state);

    Ok(rocket.into())
}
I have docker and postgresql installed, but I haven't set anything up besides starting a postgres server. The docs aren't super clear about if any setup is needed? When I try to run locally with
cargo shuttle run
, I get:
Copy code
Finished dev [unoptimized + debuginfo] target(s) in 4.51s
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: tonic::transport::Error(Transport, hyper::Error(Listen, Os { code: 48, kind: AddrInUse, message: "Address already in use" }))', /Users/brk/.cargo/registry/src/github.com-1ecc6299db9ec823/shuttle-runtime-0.17.0/src/alpha/mod.rs:87:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: status: Internal, message: "failed to connect to provisioner", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc", "date": "Sun, 28 May 2023 10:57:47 GMT", "content-length": "0"} }
Which looks like it's either not provisioning a DB (but the whole idea is that this should be automatic, right?) or the address it's trying to use is in use (But I'm not sure what by?). Could someone point me in the right direction?
I'm on a M1 Mac, MacOS 12.4,
rustc 1.69.0 (84c898d65 2023-04-16)
, Cargo.toml:
Copy code
[package]
name = "eskom-calendar-api"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
chrono = "0.4.19"
csv = "1.1"
reqwest = { version = "0.11", features = ["json"] }
rocket = { version = "0.5.0-rc.3", features = ["json"] }
shuttle-rocket = { version = "0.17.0" }
shuttle-runtime = { version = "0.17.0" }
shuttle-shared-db = { version = "0.17.0", features = ["postgres"] }
shuttle-aws-rds = { version = "0.17.0", features = ["postgres"] }
sqlx = { version = "0.6.3", features = ["runtime-tokio-native-tls", "postgres"] }
tokio = { version = "1.28.0", features = ["full"] }
s
I think you just need docker set up and able to connect with the user you are logged in as.
r
I'm afraid I'm really new to docker and postgres. When you say "setup docker", what do you mean?
I just tried to run the postgres rocket example https://github.com/shuttle-hq/shuttle-examples/tree/main/rocket/postgres and got the same error:
Copy code
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: tonic::transport::Error(Transport, hyper::Error(Listen, Os { code: 48, kind: AddrInUse, message: "Address already in use" }))', /Users/brk/.cargo/registry/src/github.com-1ecc6299db9ec823/shuttle-runtime-0.17.0/src/alpha/mod.rs:87:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: status: Internal, message: "failed to connect to provisioner", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc", "date": "Sun, 28 May 2023 11:15:21 GMT", "content-length": "0"} }
So I guess you're right, it must be something with my system
s
I just mean have docker installed and then configure your user so it can access docker...
That said, addrInUse implies a conflict with something already running. Could be something already using a port. Or something else. Sorry it hard to guess.
r
Docker is installed:
Copy code
$ docker --version
Docker version 24.0.2, build cb74dfcd85
I'm not sure why my user wouldn't be able to access it by default? (or how to give it permission if it isn't able to access it) I'm going to try shut down postgres and reinstall, which will hopefully get rid of the
addrInUse
Okay nevermind, I uninstalled postgres and docker, but still am getting the same error:
Copy code
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: tonic::transport::Error(Transport, hyper::Error(Listen, Os { code: 48, kind: AddrInUse, message: "Address already in use" }))', /Users/brk/.cargo/registry/src/github.com-1ecc6299db9ec823/shuttle-runtime-0.17.0/src/alpha/mod.rs:87:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: status: Internal, message: "failed to connect to provisioner", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc", "date": "Sun, 28 May 2023 11:28:14 GMT", "content-length": "0"} }
g
You probably have a different program listening on a port that shuttle uses
Might be 8080
r
So I tracked down the original file that's unwrapping a Err, and added a `println`: shuttle-runtime-0.17.0/src/alpha/mod.rs (https://github.com/shuttle-hq/shuttle/blob/main/runtime/src/alpha/mod.rs#L87)
Copy code
87   │     println!("{}", addr);
  88   │     router.serve(addr).await.unwrap();
  89   │ }
And it looks like the address is
127.0.0.1:7999
. When I look at the process using port 7999 via
lsof
and
Copy code
$ lsof -nP -iTCP:7999
COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
eskom-cal 19156  brk    9u  IPv4 0xbb0761ebe9a30759      0t0  TCP 127.0.0.1:7999 (LISTEN)

$ ps 19156
  PID   TT  STAT      TIME COMMAND
19156   ??  S      0:00.21 /Users/brk/projects/eskom-calendar-api/target/debug/eskom-calendar-api --port 7999 --provisioner-address http://localhost:15532 --storage-manager-type working-dir --storage-manager-path /Users/brk/projects/eskom-calendar-api
(eskom-calendar-api is the name of the project) So it seems like I did something while setting up shuttle which caused this issue. I'm going to kill the related processes and see if that helps
Okay a few things. First off,
kill -9 19156
and then
cargo shuttle run
caused everything to run smoothly. So that's good. I've confirmed that this behaviour is easy to reproduce by starting shuttle
cargo shuttle run
, sending it to the background
^Z
, and then attempting to start shuttle in a different process
cargo shuttle run
. Then the second shuttle instance will emit the same error as I was getting. I've opened a PR (https://github.com/shuttle-hq/shuttle/pull/950) to clarify the error message (basically just printing out the address which could not be found).
However there's a larger issue at play here I think. If I try to
cargo shuttle run
after ensuring that port 7999 is clear, I get this error:
Copy code
2023-05-28T13:32:29.942039Z ERROR cargo_shuttle::provisioner_server: got unexpected error while inspecting docker container: error trying to connect: No such file or directory (os error 2)
2023-05-28T13:32:29.943945Z ERROR cargo_shuttle: failed to load your service error="Custom error: failed to provision shuttle_aws_rds :: Postgres"
Which is fine, I think I just need to setup a docker. But, if I now try to run
cargo shuttle run
again, I get the original error complaining about ports not being open:
Copy code
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: tonic::transport::Error(Transport, hyper::Error(Listen, Os { code: 48, kind: AddrInUse, message: "Address already in use" }))', /Users/brk/.cargo/registry/src/github.com-1ecc6299db9ec823/shuttle-runtime-0.17.0/src/alpha/mod.rs:87:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: status: Internal, message: "failed to connect to provisioner", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc", "date": "Sun, 28 May 2023 13:42:10 GMT", "content-length": "0"} }
So I think that shuttle is not cleaning up its ports, or its leaving something running in the background. This seems like a bug?
g
Well, if you leave the process in the background, why wouldn't it complain if you try to run a new one in parallel?
r
Leaving the process in the background was just an easy way to get the same error message, in case you wanted to reproduce the bug. It's not really important now that I figured out what's causing the issue.
Although there still is the bug that it looks like cargo-shuttle doesn't clean up a process when it throws the
got unexpected error while inspecting docker container: error trying to connect: No such file or directory (os error 2)
error
Turns out
brew install docker
doesn't install the docker I needed.
brew install homebrew/cask/docker
was the correct command, and then I needed to open the app to get the docker engine started. Is there a documentation repository I could contribute to? The content on https://docs.shuttle.rs/resources/shuttle-aws-rds is great but I'd love to have a troubleshooting section.
a
I think the correct section would be here https://docs.shuttle.rs/support/troubleshooting