Hi, We’ve implemented Real-time using Redis on a Redwood project. However, we are getting an odd error locally when either debugging using console.log from services or making any file changes (e.g., updating service logic) that cause the server to rebuild.
The issue is that the server rebuilds but changes ports, and then the web no longer connects to the API, and we have to stop and run the yarn rw dev command again.
It only occurs only when we have an active subscription on a route from the web. If we navigate away from the page that has the subscription, this doesn’t happen.
Before the error, we are running on port 8910
web | ➜ Local: http://localhost:8910/
web | ➜ Network: http://192.168.0.14:8910/
Once we make a change or have a service do a console.log we get the following and then a rebuild with new port
api | 06:34:23 🐛 Processing GraphQL Parameters done.
api | [change] \src\lib\realtime.js
api | Building...
web | node:_http_server:339
web | throw new ERR_HTTP_HEADERS_SENT('write');
web | ^
web |
web | Error: Cannot write headers after they are sent to the client
web | at new NodeError (node:internal/errors:399:5)
web | at ServerResponse.writeHead (node:_http_server:339:11)
web | at ProxyServer.<anonymous> (C:\Users\saps1\Desktop\source_code_folder\Redwood.Metronic\node_modules\@redwoodjs\vite\dist\index.js:230:25)
web | at ProxyServer.emit (file:///C:/Users/saps1/Desktop/source_code_folder/Redwood.Metronic/node_modules/vite/dist/node/chunks/dep-52909643.js:62222:28)
web | at ClientRequest.proxyError (file:///C:/Users/saps1/Desktop/source_code_folder/Redwood.Metronic/node_modules/vite/dist/node/chunks/dep-52909643.js:63568:18)
web | at ClientRequest.emit (node:events:511:28)
web | at Socket.socketErrorListener (node:_http_client:495:9)
web | at Socket.emit (node:events:511:28)
web | at emitErrorNT (node:internal/streams/destroy:151:8)
web | at emitErrorCloseNT (node:internal/streams/destroy:116:3)
web | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
web | code: 'ERR_HTTP_HEADERS_SENT'
web | }
web |
web | Node.js v20.0.0
web | yarn cross-env NODE_ENV=development rw-vite-dev exited with code 1
api | Took 4364 ms
api | Debugger listening on ws://127.0.0.1:18911/ed2ddb05-e7cd-461c-b8b5-06ab641a8ca4
api | For help, see: https://nodejs.org/en/docs/inspector
api | Logs will be sent to the transport stream in the current development environment.
api | Importing Server Functions...
api | /generateProjectDetails 2374 ms
api | ...Done importing in 2375 ms
api | GraphQL Yoga Server endpoint at graphql
api | GraphQL Yoga Server Health Check endpoint at graphql/health
api | GraphQL Yoga Server Readiness endpoint at graphql/readiness
api | 06:40:41 🌲 Server listening at http://[::]:8911
api | Server listening at http://[::]:8911/
I understand that having an open subscription is causing the issue, I’m familiar with this error from my PHP days. However is there a way to keep the route with subscription open, and have the server rebuild on the same port, then have the subscription auto-reconnect? Or what is another approach?