Skip to content

Commit

Permalink
Check RPC after geth startup to reduce flakiness
Browse files Browse the repository at this point in the history
This is meant to avoid the following errors that happens across most
(all?) e2e tests from time to time:
```
 Error: Connection refused or URL couldn't be resolved: http://localhost:8545
  at XMLHttpRequest.request.onreadystatechange (/home/circleci/app/node_modules/web3-providers/dist/web3-providers.cjs.js:759:22)
  at XMLHttpRequestEventTarget.dispatchEvent (/home/circleci/app/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
  at XMLHttpRequest._setReadyState (/home/circleci/app/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
  at XMLHttpRequest._onHttpRequestError (/home/circleci/app/node_modules/xhr2-cookies/xml-http-request.ts:379:8)
  at ClientRequest.<anonymous> (/home/circleci/app/node_modules/xhr2-cookies/xml-http-request.ts:266:37)
  at Socket.socketErrorListener (_http_client.js:406:9)
  at emitErrorNT (internal/streams/destroy.js:92:8)
  at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
  at processTicksAndRejections (internal/process/task_queues.js:80:21)
```

I am not sure this actually works as intended, but I could not reproduce
the problem after this change, anymore. So it is worth testing it out,
as we can easily revert the change or improve the approach.
  • Loading branch information
karlb committed Jun 28, 2023
1 parent f1c27e8 commit 0e817f1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/celotool/src/lib/geth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,26 @@ export async function startGeth(
}
}

// Geth startup isn't fully done even when the port is open, so give it another second
await sleep(1000)
// Geth startup isn't fully done even when the port is open, so check until it responds
const maxTries = 5
let tries = 0
while (tries < maxTries) {
tries++
let block = null
try {
block = await new Web3('http://localhost:8545').eth.getBlock('latest')
} catch (e) {
console.log(`Failed to fetch test block: ${e}`)
}
if (block) {
break
}
console.log('Could not fetch test block. Wait one second, then retry.')
await sleep(1000)
}
if (tries === maxTries) {
throw new Error(`Geth did not start within ${tries} seconds`)
}

console.log(
`${instance.name}: running.`,
Expand Down

0 comments on commit 0e817f1

Please sign in to comment.