Closed dinfyru closed 8 years ago
You need to ensure you only ever call reply(result)
once per request.
@mtharrison i use once per request
I don't think the code you pasted will help us understand what you're doing wrong, it doesn't contain any hapi related code.
function cb() leads to router (example: Base.js:55)
$lib.s.route({
method: 'POST',
path:'/game',
config: {
plugins: {
'hapi-io': 'user-action'
}
},
handler: function (request, reply) {
require($lib.controllerpath + 'game/base')(callback, request, true);
function callback (err, result){
return reply(result);
}
}
});
Best guess is this.getTimeEnergy
throws an exception which triggers an implicit reply. hapi protects you from failures in your code by doing that.
The error occurs when you call at the same time 2 soket.emmit
@Marsup how i can fix it?)
@Dinfyru I advise you to try to create a minimal example that shows the problem and we can debug from there. Otherwise it's too difficult to advise. Have a look at How to create a Minimal, Complete, and Verifiable example if you need help.
I call socket.emit 2 times for route
$lib.s.route({
method: 'POST',
path:'/game',
config: {
plugins: {
'hapi-io': 'user-action'
}
},
handler: function (request, reply) {
require($lib.controllerpath + 'game/base')(callback, request, true);
function callback (err, result){
return reply(result);
}
}
});
And this return error
Debug: internal, implementation, error
Error: reply interface called twice
this
socket.emit('user-action', { userAction: 'start'}, function(res) {
socketFunc(res);
});
and this
socket.emit('user-action', { userAction: 'getTimeEnergy' }, function(res) {
$('.header .energy .text').text(res.val);
if (res.type !== 'time') {
$('.header .energy .progress').css('width', (res.val + '%'));
}
});
The error only occurs when they are called at the same time, and then they fall into one reguest (somehow)
This will fix my problem? https://github.com/mtharrison/susie In example i see many reply
reply.event({ id: 1, data: 'my data' });
setTimeout(function () {
reply.event({ id: 2, data: { a: 1 } }); // object datum
}, 500);
Or ho i can disable error (reply called twice)
I advise you to try to create a minimal example that shows the problem and we can debug from there.
This advice still stands. You're not giving us enough to help. Simply adding another library won't fix the problem.
You're mixing up websockets and normal handlers, I have no idea what you're doing there. This should really go into the discuss repo, this is not the place.
@Marsup and what i can use for websockets?
controller Base.js called callback (cb()) for use reply http://pastebin.com/B8FYEDMj I have a loop that once per second refers to the server (function - getTimeEnergy in Base.js). And sometimes there is this error "reply interface called twice"
hapi version 15.0.3 nodejs - 6.3.0