fastify / help

Need help with Fastify? File an Issue here.
https://www.fastify.io/
64 stars 8 forks source link

@nextjs/fastify throw error with socket instance with dev=false (production) mode #860

Open officefish opened 1 year ago

officefish commented 1 year ago
// just a wrapper for register fastifyNexyJS as plugin next-plugin.ts
import fastifyNextJS from '@fastify/nextjs' 
import fp from 'fastify-plugin'

const nextPlugin = fp(async (server) => {    
    server.register(fastifyNextJS, {dev:false})   
})

export { nextPlugin as NextPlugin }

//than register wrapper as plugin
fastify.register(plugins.NextPlugin)

    await fastify.after()

    fastify.next('/')
    fastify.next('/hello')
    fastify.next('/home')

What was the result you received?

That is last log before fastify crashing:

{"level":30,"time":1680213095202,"pid":18776,"hostname":"techies","reqId":"req-1","req":{"method":"GET","url":"/_next/webpack-hmr","hostname":"localhost:8001","remoteAddress":"127.0.0.1","remotePort":51543},"msg":"incoming request"} {"level":30,"time":1680213095227,"pid":18776,"hostname":"techies","reqId":"req-1","res":{"statusCode":404},"responseTime":24.596400022506714,"msg":"request completed"} node:events:491 throw er; // Unhandled 'error' event ^

Error: write ECONNABORTED at afterWriteDispatched (node:internal/stream_base_commons:160:15) at writeGeneric (node:internal/stream_base_commons:151:3) at Socket._writeGeneric (node:net:930:11) at Socket._write (node:net:942:8) at writeOrBuffer (node:internal/streams/writable:392:12) at _write (node:internal/streams/writable:333:10) at Writable.write (node:internal/streams/writable:337:10) at ServerResponse._writeRaw (node:_http_outgoing:428:17) at ServerResponse._send (node:_http_outgoing:377:15) at ServerResponse.end (node:_http_outgoing:1019:10) Emitted 'error' event on Socket instance at: at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { errno: -4079, code: 'ECONNABORTED', syscall: 'write' }

What did you expect?

Expect it working as usual.

With dev=true it is warking, but every 5 seconds send GET /_next/webpack-hmr responses and got 404 error from fastify server, because I doesn't have any routes for that.

Context

Fastify version 4.14.1

Plugin version 9.2.0

Node.js version 18.14

Operating system Windows

Operating system version (i.e. 20.04, 11.3, 10) 11.3

mcollina commented 1 year ago

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.