Skip to content

Bad file descriptor (Node.js + fastify) #867

Open
@monteeya

Description

@monteeya

I'm trying to use unit with fastify and node loader, but I'm getting get this error on start:

2023/05/04 23:33:38 [warn] 1098833#1098833 [unit] Failed to init uv.poll
2023/05/04 23:33:38 [alert] 1098833#1098833 [unit] ioctl(15, FIONBIO, 0) failed: Bad file descriptor (9)
/home/user/.npm-global/lib/node_modules/unit-http/http_server.js:406
    this.unit.createServer();
              ^

Error: Failed to create Unit object
    at new Server (/home/user/.npm-global/lib/node_modules/unit-http/http_server.js:406:15)
    at Object.createServer (/home/user/.npm-global/lib/node_modules/unit-http/http.js:15:12)
    at getServerInstance (/app/node_modules/fastify/lib/server.js:295:21)
    at GetAddrInfoReqWrap.callback (/app/node_modules/fastify/lib/server.js:141:33)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:130:8)

Application is a standard fastify hello world:

// Require the framework and instantiate it
const fastify = require('fastify')({ logger: true })

// Declare a route
fastify.get('/', async (request, reply) => {
  return { hello: 'world' }
})

// Run the server!
const start = async () => {
  try {
    await fastify.listen({ port: 3000 })
  } catch (err) {
    fastify.log.error(err)
    process.exit(1)
  }
}
start()

Application config:

{
            "type": "external",
            "working_directory": "/app/",
            "executable": "/usr/bin/env",
            "arguments": [
                "node",
                "--loader",
                "unit-http/loader.mjs",
                "--require",
                "unit-http/loader",
                "server.js"
            ]
        }

("hello world" with the default node http module works normally)

OS: Debian 11
Node version: 18.14

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions