Skip to content

Commit

Permalink
fix: rpc connect timeout (#143)
Browse files Browse the repository at this point in the history
* Increased rpc timeout on init & added env var

* Add env vars to readme
  • Loading branch information
ChaoticTempest authored Jun 2, 2022
1 parent a039d06 commit 810c210
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,9 @@ async fn test_contract() -> anyhow::Result<()> {
}
```
For a full example, take a look at [workspaces/tests/deploy_project.rs](https://github.com/near/workspaces-rs/blob/main/workspaces/tests/deploy_project.rs).


### Environment Variables
These environment variables will be useful if there was ever a snag hit:
- `NEAR_RPC_TIMEOUT_SECS`: The default is 10 seconds, but this is the amount of time beforing timing out waiting for a RPC service when talking to the sandbox or any other network such as testnet.
- `NEAR_SANDBOX_BIN_PATH`: Set this to our own prebuilt `neard-sandbox` bin path if we want to use a non-default version of the sandbox or configure nearcore with our own custom features that we want to test in workspaces.
13 changes: 10 additions & 3 deletions workspaces/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,20 @@ impl Client {
}

pub(crate) async fn wait_for_rpc(&self) -> anyhow::Result<()> {
let retry_six_times = std::iter::repeat_with(|| Duration::from_millis(500)).take(6);
Retry::spawn(retry_six_times, || async { self.status().await })
let timeout_secs = match std::env::var("NEAR_RPC_TIMEOUT_SECS") {
Ok(secs) => secs.parse::<usize>()?,
Err(_) => 10,
};

let retry_strategy =
std::iter::repeat_with(|| Duration::from_millis(500)).take(2 * timeout_secs);
Retry::spawn(retry_strategy, || async { self.status().await })
.await
.map_err(|e| {
anyhow::anyhow!(
"Failed to connect to RPC service {} within three seconds: {:?}",
"Failed to connect to RPC service {} within {} seconds: {:?}",
self.rpc_addr,
timeout_secs,
e
)
})?;
Expand Down

0 comments on commit 810c210

Please sign in to comment.