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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
shixianqin opened this issue Jun 26, 2024 · 7 comments
Closed
5 tasks done

Comments

@shixianqin
Copy link

shixianqin commented Jun 26, 2024

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

@ScriptedAlchemy
Copy link
Member

it depends on how its configured if render it attempting to use the port again then it will crash.

@ScriptedAlchemy
Copy link
Member

Ill look at the example, its quite old so probbably needs to be redone.
We are about to release SSR federation support in modernjs https://modernjs.dev/en/ so if you are looking at rolling your own ssr, this is going to be a much less painful solution with less pitfalls like waterfall or css flushing

@shixianqin
Copy link
Author

Is there a detailed or up-to-date example of the revalidate method?

@ScriptedAlchemy
Copy link
Member

You want to clear the require cache when hash is different.
Im guessing your server entrypoint is getting cleared and re-required as well.

I can take a look at your repo and see. What are steps to reproduce? Just update remote and refresh and it crashed?

@shixianqin
Copy link
Author

After both services are started:

  1. Modify the app2 code
  2. Refresh the app1 page
  3. Then the app1 server crashed

@ScriptedAlchemy
Copy link
Member

okay will check it out

Copy link
Contributor

Stale issue message

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants