TooTallNate/node-weak

the Expressjs server silently crashes

felixhao28 opened this issue · 0 comments

I am using node v10.12.0 on Windows 10 x64. After the expressjs server runs for a while, having handled a few thousands requests (the number varied for each run, the requests for each run are exactly the same, including both order and contents), the server simply crashed without error message. I have added these error handlers but none logged anything for me:

    process.on('uncaughtException', function (exception) {
        console.log(exception);
    });
    process.on('unhandledRejection', function (exception) {
        console.log(exception);
    });
    process.on('exit', function (exception) {
        console.log('exit'); // even this line never gets printed
        console.log(exception);
    });
    app.use((err: any, req: Request, res: Response, next: NextFunction) => {
        console.error(err.stack)
        res.status(500).send('Something broke!') // client never received 500 code
    });

The only thing I got the error code "-1073741819", using echo %ERRORLEVEL% on command line.

The way I use node-weak is to store a weak reference in a Queue from typescript-collections and check if it has desired member "timestamp":

    addToEntry(node: TrieNode<T>) {
        this.expireQueue.add([new Date().getTime(), weak(node)]);
        this.nodeCount++;
        while (this.nodesLimit < this.nodeCount) {
            const [timestamp, deleteNode] = this.expireQueue.dequeue() as [number, TrieNode<T>];
            if (deleteNode.timestamp && timestamp >= deleteNode.timestamp) {
                this.deleteNode(deleteNode);
            }
        }
    }

After I switch weak(node) to node, crashing stopped happening. I am sorry for being unable to offer you full code to reproduce the bug (because it is proprietary) or more information (because I don't know more).