REALLY ready really means REALLY ready (#60652)

* Added a ping before displaying banner

* added comment about NODE_TLS

* updated typing imports
This commit is contained in:
James McNamara 2024-02-21 12:10:24 -08:00 committed by GitHub
parent c16806485f
commit 0fd7e9e1da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 4 deletions

View File

@ -66,7 +66,8 @@ export const esbuildDevelopmentServer = async (
const proxyServer = proxyApp.listen(listenAddress)
// eslint-disable-next-line @typescript-eslint/return-await
return await new Promise<void>((_resolve, reject) => {
proxyServer.once('listening', () => {
proxyServer.once('listening', async () => {
await pingUntilReady({ url: HTTPS_WEB_SERVER_URL })
signale.success(`esbuild server is ready after ${Math.round(performance.now() - start)}ms`)
printSuccessBanner(['✱ Sourcegraph is really ready now!', `Click here: ${HTTPS_WEB_SERVER_URL}/search`])
})
@ -74,6 +75,40 @@ export const esbuildDevelopmentServer = async (
})
}
interface PingOptions {
url: string
backoffMillis?: number
factor?: number
maxBackoffMillis?: number
}
function pingUntilReady({
url,
backoffMillis = 500,
factor = 1.5,
maxBackoffMillis = 10000,
}: PingOptions): Promise<void> {
const ping = (backoff: number) => (resolve: () => void) => {
fetch(url)
.then(response => {
if (response.ok) {
resolve()
} else {
throw new Error(`${url} produced ${response.status} ${response.statusText}`)
}
})
.catch(console.error)
.then(sleep(backoff))
.then(() => ping(Math.min(backoff * factor, maxBackoffMillis))(resolve))
}
return new Promise(ping(backoffMillis))
}
function sleep(ms: number): () => Promise<void> {
return () => new Promise(resolve => setTimeout(resolve, ms))
}
if (require.main === module) {
async function main(args: string[]): Promise<void> {
if (args.length !== 0) {

View File

@ -408,6 +408,8 @@ commands:
pnpm run generate
env:
ENABLE_OPEN_TELEMETRY: true
# Needed so that node can ping the caddy server
NODE_TLS_REJECT_UNAUTHORIZED: 0
web-standalone-http:
description: Standalone web frontend (dev) with API proxy to a configurable URL
@ -598,8 +600,6 @@ commands:
env:
SYNTACTIC_CODE_INTEL_WORKER_ADDR: 127.0.0.1:6076
executor-template:
&executor_template # TMPDIR is set here so it's not set in the `install` process, which would trip up `go build`.
cmd: |
@ -1231,7 +1231,6 @@ commandsets:
- syntactic-code-intel-worker-0
- syntactic-code-intel-worker-1
codeintel:
requiresDevPrivate: true
checks: