Unitech / Unitech/pm2

Socketio Cross-Origin Request Blocked error with PM2

Open
#5,154 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

I am using PM2 with cluster mode for my node application. I follow socketio code example (https://socket.io/docs/v4/cluster-adapter/#With-PM2 ).

After that I am getting Cross-Origin Request Blocked error. If I run application on two node, then I am getting 200 for some request and for rest getting error.

image

I also follow socketio documentation (https://socket.io/docs/v4/handling-cors/) to resolve this issue but no luck. following is my code for that

 const httpServer = createServer(app);
 const io = new Server(httpServer,{
 cors: {
    origin: ["*"],
    methods: ["GET", "POST"],
    credentials: true
 },
 transports: ["polling"],
 allowEIO3: true
 }); 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PM2 cluster adapter example and Socket.IO's CORS documentation linked in the issue, then reproduce the behavior with two Node processes, polling, and the shown server options. Done means identifying whether the intermittent CORS failures come from PM2 clustering or the Socket.IO configuration and documenting a verified resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, devops, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.