oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.01k stars 2.66k forks source link

RangeError: Maximum call stack size exceeded #11866

Closed achraf-workspace closed 2 months ago

achraf-workspace commented 2 months ago

What version of Bun is running?

1.1.13

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

create a new project with two files:

server.ts

import express, { Request, Response } from 'express';
import { BrokerClient } from './brokerClient';

const app = express();
const port = 3000; // change this to your desired port

app.get('/', (_req: Request, res: Response) => {
    res.send('Hello, World!');
});

app.listen(port, () => {
    console.info(`Server is running at http://localhost:${port}`);

    const brokerClient = new BrokerClient();
    brokerClient.activate();

    brokerClient.getClient().onConnect = function (frame) {
        console.info('Connected to STOMP');
    };

    brokerClient.getClient().onStompError = function (frame) {
        console.error('Got error on STOMP connection: ', frame);
    };
});

brokerClient.ts

import { Client } from '@stomp/stompjs';
// @ts-ignore
global.WebSocket = require('ws')

export class BrokerClient {
    private client: Client;

    constructor() {
        this.client = new Client();

        const brokerClientOptions = {
            brokerURL: '<brokerurl>,
            password: '<password>'
        };

        this.client.configure({
            brokerURL: brokerClientOptions.brokerURL,
            connectHeaders: {
                login: '<login>',   // you might want to change this if you have a different login
                passcode: brokerClientOptions.password
            },
            debug: function (str) {
                console.debug(str);
            },
            reconnectDelay: 5000,
            heartbeatIncoming: 4000, 
            heartbeatOutgoing: 4000,
        });

    }

    activate() {
        this.client.activate();
    }

    getClient() {
        return this.client;
    }
}

package.json

{
    "name": "stomp-express-app",
    "version": "1.0.0",
    "description": "Express Server with STOMP Broker Client",
    "main": "server.ts",
    "scripts": {
        "start:bun": "bun --watch run src/server.ts",
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [
        "STOMP",
        "Express",
        "Node.js"
    ],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "@stomp/stompjs": "^6.1.0",
        "express": "^4.17.1",
        "ts-node": "^10.9.2",
        "ws": "^8.17.0"
    },
    "devDependencies": {
        "@types/bunyan": "^1.8.11",
        "@types/express": "^4.17.21",
        "typescript": "4.3.4"
    }
}
  1. install dependencies with bun install
  2. use bun --watch run src/server.ts to run the server

What is the expected behavior?

server runs properly and brokerClient is connected without an issue.

What do you see instead?

I see the following error in my terminal

Server is running at http://localhost:3000
Opening Web Socket...
71 |   static CLOSED = 3;
72 |   #ws;
73 |   #paused = !1;
74 |   #fragments = !1;
75 |   #binaryType = "nodebuffer";
76 |   constructor(url, protocols, options) {
                  ^
RangeError: Maximum call stack size exceeded.
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)
      at new WebSocket (ws:76:14)

Bun v1.1.13 (macOS arm64)

Additional information

No response

achraf-workspace commented 2 months ago

@Jarred-Sumner thanks for the quick intervention. The error is gone but now my server is stuck in the following loop

Opening Web Socket...
Connection closed to <BROKER_URL>
STOMP: scheduling reconnection in 5000ms
Opening Web Socket...
Connection closed to <BROKER_URL>
STOMP: scheduling reconnection in 5000ms
Opening Web Socket...
Connection closed to <BROKER_URL>
STOMP: scheduling reconnection in 5000ms

when running the same server with Node.js:

Server is running at http://localhost:3000
Opening Web Socket...
Web Socket Opened...
>>> CONNECT
login:<LOGIN>
passcode:<PASSCODE>
accept-version:1.0,1.1,1.2
heart-beat:4000,4000

Received data
<<< CONNECTED
version:1.2
session:ID:<SESSION_ID>
heart-beat:4000,4000
server:ActiveMQ/5.15.16
content-length:0

connected to server ActiveMQ/5.15.16
send PING every 4000ms
check PONG every 4000ms
Connected to STOMP
Jarred-Sumner commented 2 months ago

@achraf-workspace i suggest filing a new issue for that. Might be related to #5627