Skip to content

Socket IO 4.3 Breaks HTTPS Support #4124

@Striar-Yunis

Description

@Striar-Yunis

Describe the bug
4.2 -> 4.3 added this if statement check:

if (srv instanceof http.Server || typeof srv === "number") {

That check means that servers made with the https module won't be bound:

To Reproduce
Socket.IO server version: 4.3.0

Server

const { readFileSync } = require("fs");
const { createServer } = require("https");
const { Server } = require("socket.io");

const httpServer = createServer({
  key: readFileSync("/path/to/my/key.pem"),
  cert: readFileSync("/path/to/my/cert.pem")
});

const io = new Server(httpServer, { /* options */ });

io.on("connection", (socket) => {
  // ...
});

httpServer.listen(3000);

^ From https://socket.io/docs/v4/server-initialization/#with-an-https-server

Expected behavior
The https server should be attached. It isn't. You can see this by modifying the following in the /dist/index.js

console.log('look for this 1');
if (srv instanceof http.Server || typeof srv === "number") {
    console.log('look for this 2');
    this.attach(srv);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions