Skip to content

Commit

Permalink
add timeout option to getFastifyServerAddress()
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Jan 24, 2024
1 parent a772a42 commit 3aafbc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/fastify-plugins/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { once } from 'node:events'

/**
* @param {import('node:http').Server} server
* @param {{ timeout?: number }} [options]
* @returns {Promise<string>}
*/
export async function getFastifyServerAddress(server) {
export async function getFastifyServerAddress(server, { timeout } = {}) {
const address = server.address()

if (!address) {
await once(server, 'listening')
await once(server, 'listening', {
signal: timeout ? AbortSignal.timeout(timeout) : undefined,
})
return getFastifyServerAddress(server)
}

Expand Down
5 changes: 2 additions & 3 deletions src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { eq } from 'drizzle-orm'
import { drizzle } from 'drizzle-orm/better-sqlite3'
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import Hypercore from 'hypercore'
import pTimeout from 'p-timeout'
import { TypedEmitter } from 'tiny-typed-emitter'

import { IndexWriter } from './index-writer/index.js'
Expand Down Expand Up @@ -237,8 +236,8 @@ export class MapeoManager extends TypedEmitter {
}
}

const base = await pTimeout(getFastifyServerAddress(this.#fastify.server), {
milliseconds: 1000,
const base = await getFastifyServerAddress(this.#fastify.server, {
timeout: 5000,
})

return base + '/' + prefix
Expand Down

0 comments on commit 3aafbc0

Please sign in to comment.