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

Socket.io returns Error: xhr poll error on connect on some client browsers #4118

Closed
justlester opened this issue Oct 13, 2021 · 4 comments
Closed
Labels
unable to reproduce We were unable to reproduce the issue

Comments

@justlester
Copy link

Describe the bug
Hi! I have a socket server that is not of the same origin as my website. Some of my users are unable to connect and always return the XHR poll error upon connecting (status code 0). We've also tried other browsers but still the same error.
I found out also that the user's browser is unable to perform a GET/POST request on my socket server (status code 0).
It's kinda weird that most of the users are connected and able to request from the server.

I am unable to replicate it on my end. Is this something on their ISP or browser settings?

Server
express version: ^4.17.1
cors: ^2.8.5
Socket.IO server version: ^4.0.1

const path = require('path');
const http = require('http');
const express = require('express');
const cors = require('cors');
const socketio = require('socket.io');
const createNotificationObject = require('./utils/notifications');

const whitelist =  [...];
var corsOptions = {
    origin: function (origin, callback) {
        if (whitelist.indexOf(origin) !== -1 || !origin) {
            callback(null, true)
        } else {
            callback(new Error('Not allowed by CORS'))
        }
    }
}
var onlineUsers = {};

const app = express();
app.use(express.json({limit:'1mb'}));

app.all('*',cors(corsOptions),function(req,res,next){
    next();
});

const server = http.createServer(app);

const io = socketio(server,{
    allowEIO3: true,
    cors: {
        origin: whitelist,
        methods: ["GET", "POST"],
        credentials: true
    }
});

app.post('/emit-notification',function(req,res){
    console.log(req.body);
    io.emit('notification',createNotificationObject(req.body));
    res.json({
        statusText: 'success',
        status: 200
    });
});

//Run when client connects
io.on('connection',socket=>{
    console.log(`Successfully connected`);

    socket.on('online', function(data){
        console.log(`User ${(userinfo && userinfo.Id) || ''} connected`);
    });

});

const PORT = process.env.PORT || 3000; 

server.listen(PORT,()=> console.log(`Server running on port ${PORT}`));

Socket.IO client version: ^4.1.3

Client

const socketServer = '...';
var socket = io(socketServer);
socket.on('connect', () => {
    console.log('SOCKET SERVER CONNECTED: ',socket.connected);
});

socket.on('notification',payload =>{
      console.log('NEW NOTIFICATION',payload);
});

Expected behavior
Should connect to the socket server

Platform:

  • Browser: Chrome 94.0.4606.81
  • OS: Windows 10
@justlester justlester added the bug Something isn't working label Oct 13, 2021
@darrachequesne
Copy link
Member

Hi! That's weird indeed. Do you know their OS/browser setup? Could it be SSL related?

@justlester
Copy link
Author

I found the cause. It was a DNS issue. I just set their primary DNS to cloudflare (1.1.1.1) and the secondary DNS to google (8.8.8.8).

@justlester
Copy link
Author

Hi! That's weird indeed. Do you know their OS/browser setup? Could it be SSL related?

The domain is already secured. I'm not sure why their default DNS is not allowing connection with my server.

@darrachequesne
Copy link
Member

OK, thanks for the update! 👍

I'm going to close this, as I don't think this is directly related to Socket.IO. Please reopen if needed.

@darrachequesne darrachequesne added unable to reproduce We were unable to reproduce the issue and removed bug Something isn't working labels Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unable to reproduce We were unable to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants