core icon indicating copy to clipboard operation
core copied to clipboard

Using the `revalidate` method to trigger hot reload can cause service crashes

Open shixianqin opened this issue 1 year ago • 7 comments

Describe the bug

When I use the example React-18-server-2-server for debugging, touching a hot update will cause the service to crash and prompt port :3000 is occupied. Is my posture incorrect?

// react-18-server-2-server/app1/src/server/server-entry.ts

import { revalidate } from '@module-federation/node/utils'

export default () => async (req, res, next) => {
  await revalidate().then((shouldUpdate) => {
    console.log({ shouldUpdate })
    if (shouldUpdate) {
      // reload
    }
  })

  const renderer = (await import('./render')).default
  return renderer(req, res, next)
};

Error messages 👇:

app2 hash is different - must hot reload server
@babel/polyfill is loaded more than once on this page. This is probably not desirable/intended and may have consequences if different versions of the polyfills are applied sequentially. If you do need to load the polyfill more than once, use @babel/polyfill/noConflict instead to bypass the warning.
node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1872:16)
    at listenInCluster (node:net:1920:12)
    at Server.listen (node:net:2008:7)

Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1899:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 3000
}

Reproduction

https://github.com/shixianqin/react-18-server-2-server

Used Package Manager

pnpm

System Info

System:
    OS: macOS 14.5
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 187.31 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - /usr/local/bin/node
    npm: 10.2.4 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 126.0.6478.126
    Safari: 17.5

Validations

shixianqin avatar Jun 26 '24 10:06 shixianqin