Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization error in v3.0.0-rc.5 #2374

Closed
rqbazan opened this issue Jul 6, 2020 · 2 comments 路 Fixed by fastify/avvio#114
Closed

Initialization error in v3.0.0-rc.5 #2374

rqbazan opened this issue Jul 6, 2020 · 2 comments 路 Fixed by fastify/avvio#114
Labels
bug Confirmed bug v3.x Issue or pr related to Fastify v3

Comments

@rqbazan
Copy link

rqbazan commented Jul 6, 2020

馃悰 Bug Report

When I use an asynchronous factory function to create a Fastify instance, the return value from the promise is always undefined. Btw, this problem is not present in the v2.15.1

To Reproduce

I've created a repo (https://github.com/rqbazan/fastify-issue-async) to illustrate the issue, and compare it with v2

const fastify = require('fastify') // v3.0.0-rc.5

async function buildApp(opts) {
  const app = fastify(opts)

  // register plugins

  return app
}

async function main() {
  const app = await buildApp({ logger: true })

  console.log({ app: !!app }) // false

  try {
    await app.listen(3000)
  } catch (error) {
    console.log(error)
    process.exit(1)
  }
}

main()

Expected behavior

Start the server without initialization problems, like in the v2

Your Environment

  • node version: 12.16.2
  • fastify version: 3.0.0-rc.5
  • os: Windows
@delvedor
Copy link
Member

delvedor commented Jul 6, 2020

Hello! Thank you for reporting, I confirm it's a bug.

@delvedor delvedor added bug Confirmed bug v3.x Issue or pr related to Fastify v3 labels Jul 6, 2020
@delvedor
Copy link
Member

delvedor commented Jul 6, 2020

If you return the app wrapped in an object from buildApp, the problem disappears.

async function buildApp(opts) {
  const app = fastify(opts)

  // register plugins

  return { app }
}

I think the reason is that app has a then method, which will be resolved to undefined by the async function.

mcollina added a commit to fastify/avvio that referenced this issue Jul 6, 2020
mcollina added a commit to fastify/avvio that referenced this issue Jul 6, 2020
* Make .then() resolve to the server instance

Fixes fastify/fastify#2374

* Comment

* Added more tests and resolved typo

* remove useless assertion
mcollina added a commit that referenced this issue Jul 6, 2020
mcollina added a commit that referenced this issue Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug v3.x Issue or pr related to Fastify v3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants