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

zeromq with express crashing in v8 garbage collection #259

Closed
iasna opened this issue Jun 10, 2018 · 4 comments
Closed

zeromq with express crashing in v8 garbage collection #259

iasna opened this issue Jun 10, 2018 · 4 comments

Comments

@iasna
Copy link

iasna commented Jun 10, 2018

I'm stress testing my application, after increasing the number of connections application crashes with following coredumps.
1)
0x0000000000af90b6 in v8::Exception::Error(v8::Localv8::String) ()
#6 0x00007f793b4b1912 in zmq::Socket::Unmonitor() () from /home/oracle/git2/Iris5/Core/node_modules/zeromq/build/Release/zmq.node
#7 0x00007f793b4b1cff in zmq::Socket::~Socket() () from /home/oracle/git2/Iris5/Core/node_modules/zeromq/build/Release/zmq.node
#8 0x00007f793b4b1d71 in zmq::Socket::~Socket() () from /home/oracle/git2/Iris5/Core/node_modules/zeromq/build/Release/zmq.node
#9 0x0000000000e4941e in v8::internal::GlobalHandles::DispatchPendingPhantomCallbacks(bool) ()
#10 0x0000000000e4968a in v8::internal::GlobalHandles::PostGarbageCollectionProcessing(v8::internal::GarbageCollector, v8::GCCallbackFlags) ()
#11 0x0000000000e78767 in v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) ()
#12 0x0000000000e795be in v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) ()
#13 0x0000000000e1d502 in v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) ()
#14 0x00000000010962c0 in v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) ()

#6 0x00007f6ea0c8195e in zmq_close (s_=0x4e223a22646d6322) at src/zmq.cpp:263
#7 0x00007f6ea0eb389e in zmq::Socket::Unmonitor() () from /home/oracle/git2/Iris5/Core/node_modules/zeromq/build/Release/zmq.node
#8 0x00007f6ea0eb3cff in zmq::Socket::~Socket() () from /home/oracle/git2/Iris5/Core/node_modules/zeromq/build/Release/zmq.node
#9 0x00007f6ea0eb3d71 in zmq::Socket::~Socket() () from /home/oracle/git2/Iris5/Core/node_modules/zeromq/build/Release/zmq.node
#10 0x0000000000e4941e in v8::internal::GlobalHandles::DispatchPendingPhantomCallbacks(bool) ()
#11 0x0000000000e4968a in v8::internal::GlobalHandles::PostGarbageCollectionProcessing(v8::internal::GarbageCollector, v8::GCCallbackFlags) ()
#12 0x0000000000e78767 in v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) ()
#13 0x0000000000e795be in v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) ()
#14 0x0000000000e1d84e in v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) ()
#15 0x00000000010ab96b in v8::internal::Object* v8::internal::(anonymous namespace)::SearchRegExpMultiple(v8::internal::Isolate*, v8::internal::Handlev8::internal::String, v8::internal::Handlev8::internal::JSRegExp, v8::internal::Handlev8::internal::RegExpMatchInfo, v8::internal::Handlev8::internal::JSArray) ()

Below is my code


const app = require("express");
let appObj = app();
const server = require("http");
const bodyParser = require("body-parser");
require('body-parser-xml')(bodyParser);
const zeromq = require("zeromq");
const msgpack = require("msgpack5");
var msgpk = msgpack();

function uuidv4() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}
    let serverObj = server.createServer(appObj);
    appObj.use(bodyParser.json());
    appObj.use(bodyParser.xml());
    appObj.use(function (req, res, next) {
		console.log("request received");
		res.locals.LOG_ID = uuidv4();
        next();
    });
   
    appObj.all('/*', function (req, res, next) {
        let internalRequest = req.body;
        let internalQueue = zeromq.socket('dealer');
        internalQueue.identity = res.locals.LOG_ID;
        internalQueue.connect('tcp://127.0.0.1:8111');
        try {
            internalRequest.CLIENT_ID = internalQueue.identity;
            let raw = msgpk.encode(internalRequest);
            internalQueue.send(['', raw]);
            let hasMessage = false;
            let messageFunc = function (delimiter, msg) {
                hasMessage = true;
                console.log(`${res.locals.LOG_ID} Response received from other process`);
                let decodedMsg = msgpk.decode(msg);
                console.log(decodedMsg);
                internalQueue.removeListener('message', messageFunc);
                internalQueue.close();
                console.log(`${res.locals.LOG_ID} Sending response to client `);
                res.status(200).json(decodedMsg);
            };
            internalQueue.on('message', messageFunc);
        }
        catch (error) {
            logger_.logError(`${res.locals.LOG_ID} Error occurred ${error.message}`);
            next(error);
        }
    });
    appObj.use(function (err, req, res, next) {
        if (err) {
            console.log(`${res.locals.LOG_ID} Error occurred : ${err.message}`);
			      res.status(500).send(`${err.message}`);
        }
        
    });
    serverObj.listen(6666);
@xemasiv
Copy link

xemasiv commented Jul 9, 2018

@iasna have you figured out why this happens?

@iasna
Copy link
Author

iasna commented Jul 10, 2018

yeah, the internal max socket limit of zeromq is 1024, whenever limit is reached socket creations goes in error properly. But due to some reason socket close call crashes whenever the limit is reached, i was looking into in to close code, it calls zmq_socket_monitor which was causing the crash. I increased the internal socket limit of the existing context. Furthermore, I used the connection pool to avoid frequent close, by doing this I have totally avoided that crash flow. But it may still crash when file descriptors limit is reached and close is called.

@rolftimmermans
Copy link
Member

Recently we have released 6.0 beta. It features a new API that addresses some fundamental issues with the previous API and also addresses a number of stability bugs. To make upgrading easier it includes a compatibility layer with versions 4.x/5.x. It would be great if you could give the latest version a spin to see if this solves this particular issue. If you run into any problems with it, feel free to report it here or in a new issue.

@aminya
Copy link
Member

aminya commented Aug 13, 2024

v6 was released. Please try again with the latest version, and report back if the issue still persists.
https://github.com/zeromq/zeromq.js/releases/tag/v6.0.0

@aminya aminya added the wontfix label Sep 16, 2024
@aminya aminya closed this as completed Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants