Messed up response
Opened this issue · 2 comments
Hi,
when running NGRest via callbacks, I get sometimes rest responses that are corrupted, somehow resulting in the mixing of two or more different responses to different requests.
I think the cause is that the callbacks take more time to be processed now than before, when I was not facing the issue. But I am not sure.
I tried with the Handler::post, but I get no response at all.
Is this a known issue?
Thanks.
This is a little snippet of my code:
static void serviceStatus(ngrest::Callback<const std::vector<kpsr::admin::ServiceStateData>>& callback,
const kpsr::admin::AdministrationRequest & request) {
if (!kpsr::admin::memstg::MemoryAdminCommsProvider::instance()._isInitialized) {
ngrest::Exception exception("", "serviceStatus", "communications not yet iniialised.");
callback.error(exception);
return;
}
std::function<void(kpsr::admin::AdministrationResponse)> adminResponseListener = [&callback] (const kpsr::admin::AdministrationResponse & response){
ngrest::Handler::post([&callback, &response]{
callback.success(response.serviceStateData);
});
};
kpsr::admin::memstg::MemoryAdminCommsProvider::instance().adminCallbackHandler->callbackHandler.requestAndReply(request, adminResponseListener);
}
static void serviceStatistics(ngrest::Callback<const std::vector<kpsr::admin::ServiceStatistics>>& callback,
const kpsr::admin::AdministrationRequest & request) {
if (!kpsr::admin::memstg::MemoryAdminCommsProvider::instance()._isInitialized) {
ngrest::Exception exception("", "serviceStatistics", "communications not yet iniialised.");
callback.error(exception);
return;
}
std::function<void(kpsr::admin::AdministrationResponse)> adminResponseListener = [&callback] (const kpsr::admin::AdministrationResponse & response){
ngrest::Handler::post([&callback, &response]{
callback.success(response.serviceStatistics);
});
};
kpsr::admin::memstg::MemoryAdminCommsProvider::instance().adminCallbackHandler->callbackHandler.requestAndReply(request, adminResponseListener);
}
Do you use ngrestserver or module for apache/nginx? The last still doesn't work at all.
Also the problem may be caused due to unexpected freeing of the internal data which is allocated inside service wrapper.
Please start your service using ngrestserver under Valgrind, If there any memory errors please say.