Recently we are testing Node.js with C++ addon for request processing scalability.
Please follow the below steps for more understanding:
We registered a callback function of the Node.js in C++ addon..which is called (callback) from the C++ addon whenever a request comes in.
Initial request will hit C++ addon first then it will hit the Node.js callback function.
However, if we put a load of requests more than an hour or so ..it crashes with the error I provided above.
Please look at the below code. The initial call is sendData
:
struct Work {
int status;
uv_work_t request;
string data;
Persistent<Function> callback;
};
static void WorkAsync(uv_work_t *req) {
//Work *work = static_cast<Work *>(req->data);
}
static void WorkAsyncComplete(uv_work_t *req, int status) {
Isolate * isolate = Isolate::GetCurrent();
v8::HandleScope handleScope(isolate); // Required for Node 4.x
Work *work = static_cast<Work *>(req->data);
Handle<Value> argv[1];
argv[0] = String::NewFromUtf8(isolate, work->data.c_str());
Local<Function>::New(isolate, m_work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
pthread_mutex_unlock(&queue_mutex);
}
void sendData(std::string str) {
pthread_mutex_lock(&queue_mutex);
m_work->data = str;
uv_queue_work(uv_default_loop(),&m_work->request, WorkAsync, WorkAsyncComplete);
}
Thanks