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

Keep getting and posting /socket.io/?EIO=3&transport=polling&t= #3615

Closed
chengtie opened this issue Jun 25, 2020 · 9 comments
Closed

Keep getting and posting /socket.io/?EIO=3&transport=polling&t= #3615

chengtie opened this issue Jun 25, 2020 · 9 comments

Comments

@chengtie
Copy link

chengtie commented Jun 25, 2020

My backend in ExpressJS and NodeJS used to work well. I just realized that logs exploded the disk (the backend is still functional), because when the backend is on, it keeps trying:

kpi.js GET /socket.io/?EIO=3&transport=polling&t=NBiaEK6
index.js GET /socket.io/?EIO=3&transport=polling&t=NBiaEK6
index.js router.get *
kpi.js POST /socket.io/?EIO=3&transport=polling&t=NBiaER6
index.js POST /socket.io/?EIO=3&transport=polling&t=NBiaER6
Error: Not Found
    at /opt/funfun/app.js:99:13
    at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
    at /opt/funfun/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
    at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
    at /opt/funfun/node_modules/express/lib/router/index.js:635:15
    at next (/opt/funfun/node_modules/express/lib/router/index.js:260:14)
    at /opt/funfun/routes/index.js:18:2
    at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
    at /opt/funfun/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
    at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/opt/funfun/node_modules/express/lib/router/index.js:174:3)
    at router (/opt/funfun/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
    at /opt/funfun/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
    at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
    at /opt/funfun/node_modules/express/lib/router/index.js:635:15
kpi.js GET /socket.io/?EIO=3&transport=polling&t=NBiaF8A
index.js GET /socket.io/?EIO=3&transport=polling&t=NBiaF8A
index.js router.get *
kpi.js POST /socket.io/?EIO=3&transport=polling&t=NBiaFFz
index.js POST /socket.io/?EIO=3&transport=polling&t=NBiaFFz
Error: Not Found
    at /opt/funfun/app.js:99:13
    at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
    at /opt/funfun/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
    at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
    at /opt/funfun/node_modules/express/lib/router/index.js:635:15
    at next (/opt/funfun/node_modules/express/lib/router/index.js:260:14)
    at /opt/funfun/routes/index.js:18:2
    at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
    at /opt/funfun/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
    at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/opt/funfun/node_modules/express/lib/router/index.js:174:3)
    at router (/opt/funfun/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/opt/funfun/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/funfun/node_modules/express/lib/router/index.js:317:13)
    at /opt/funfun/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/opt/funfun/node_modules/express/lib/router/index.js:335:12)
    at next (/opt/funfun/node_modules/express/lib/router/index.js:275:10)
    at /opt/funfun/node_modules/express/lib/router/index.js:635:15

kpi.js GET ... and index.js GET ... are what I print. Here is the code of opt/funfun/app.js:

// catch 404 and forward to error handler
app.use(function (req, res, next) {
  var err = new Error('Not Found');  // line 99
  err.status = 404;
  next(err);
});

Does anyone know what may be the reason?

@SibiAkkash
Copy link

I am getting the same error too

@hmagrahi
Copy link

Same error

@ven
Copy link

ven commented Jul 14, 2020

Are you accessing this through a reverse proxy? Creating a rewrite rule fixed this for me.

@kfirprods
Copy link

Are you accessing this through a reverse proxy? Creating a rewrite rule fixed this for me.

I am getting this error using a reverse proxy. Would you please share with us the rewrite rule that fixed it?

@saurav111
Copy link

Same, please do share

@ven
Copy link

ven commented Jul 26, 2020

Hi,

Try this:

server {
    listen 80;
    server_name YOURDOMAIN.COM;
    client_max_body_size 100M;
    location /socket.io/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_pass http://localhost:PORTNUMBER/socket.io/;
    }
}

@AvalancheAccessories
Copy link

Hi,

Try this:

server {
    listen 80;
    server_name YOURDOMAIN.COM;
    client_max_body_size 100M;
    location /socket.io/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_pass http://localhost:PORTNUMBER/socket.io/;
    }
}

Where would i put this code?

@darrachequesne
Copy link
Member

@AvalancheAccessories this is the configuration for NginX, used as a reverse proxy in front of your Socket.IO server(s)

Reference: https://socket.io/docs/v4/reverse-proxy/#nginx

Regarding the initial issue, the multiple requests might be due to a v2 client which tries to connect.

For v3 and above, you need to enable backward compatible mode on the server side:

import { Server } from "socket.io";

const io = new Server({
  allowEIO3: true
});

Reference: https://socket.io/docs/v4/server-options/#alloweio3

You can check those specific errors by listening to the connection_error event:

io.engine.on("connection_error", (err) => {
  if (err.code === 5) {
    // Unsupported protocol version
  }
});

Reference: https://socket.io/docs/v4/server-api/#event-connection_error

@sampete1997
Copy link

hi,
I have node js server with express and react js client in local. in local socket io is working fine but when i deployed to aws ec2 instance I am getting 404 status error

server

import express, { Express, Response, Request, NextFunction } from "express";
import bodyParser from "body-parser";
import cors from "cors";
import ErrorHandler from "./utils/errorHandler";
import MongoService, { Collections } from "./utils/mongo";
import http from 'http'
import socketIO from "socket.io";

const app: Express = express();
const PORT = process.env.PORT;

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ limit: "1mb" }));
app.use(cors());
const server = http.createServer(app);

export const io = new socketIO.Server(server, {
  cors: {
    origin: "*",  
    methods: ["GET", "POST"],
  },
});

io.on("connection", (socket) => {
    console.log(
      "connection successful! \n user connected ID: ",
      socket.id,
      "\n"
    );
    
    socket.on("disconnect", () => {
      console.log("Disconnected", "\n user ID: ", socket.id, "\n");
    });
  });
export const IO = io;

MongoService.init().then(() => {
  server.listen(PORT, async () => {
    await seed();
    console.log(`Server running at ${PORT}`);
  });
});

client

import io from 'socket.io-client';
// export const BACKEND_URL = 'http://localhost:3001';
export const BACKEND_URL = 'https://mywsbackend.tech';
export const socket = io(BACKEND_URL,{withCredentials: false, rejectUnauthorized: false}); //connecting to socket server
socket.on("connect_error", (err) => {
  console.log(`connect_error due to ${err.message}`);
});

aws ec2 logs

0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8PKY 404 149 - 0.493 ms
0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8PL1 404 149 - 0.417 ms
0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8Pjr 404 149 - 0.447 ms
0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8Qme 404 149 - 0.459 ms
0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8RBb 404 149 - 0.451 ms
0|index  | GET / 200 24 - 0.487 ms
0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8SEW 404 149 - 0.438 ms
0|index  | GET /socket.io/?EIO=4&transport=polling&t=OeD8SF0 404 149 - 0.417 ms

REQUEST HEADER

Request URL:
https://mywsbackend.tech/socket.io/?EIO=4&transport=polling&t=OeD7QRi
Request Method:
GET
Status Code:
404
Remote Address:
#########
Referrer Policy:
strict-origin-when-cross-origin

:Authority:
mywsbackend.tech
:Method:
GET
:Path:
/socket.io/?EIO=4&transport=polling&t=OeD7QRi
:Scheme:
https
Accept:
*/*
Accept-Encoding:
gzip, deflate, br
Accept-Language:
en-US,en;q=0.9
Origin:
http://localhost:3000
Referer:
http://localhost:3000/
Sec-Fetch-Dest:
empty
Sec-Fetch-Mode:
cors
Sec-Fetch-Site:
cross-site

everything is working fine in local getting issue in aws server only please help to fix this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants