In my browser I display a lot of thumbs. If a thumb is not visible (out of the viewport), I set the src to '' (empty string). And when it is in the viewPort I set the correct src.
If the user uses his scrollbar, then the download of the thumbs that are not downloaded yet are canceled by the browser.
But on the server side, some of the requests becomes 'zombie' and can fill the sockets pool (maxSockets). After the timeout, the server will kill those sockets and the pile of un-downloaded thumbs restarts.
So I need to detect that a request is canceled by the Browser in order to end response. I tried many events, without result.
function(req, res) {
var stream;
stream = getThumb(req.file.binary.thumb);
req.on('close', function() {
return console.log("reQ.on close");
});
req.connection.on('close', function() {
return console.log('reQ.connection.on close');
});
req.on('end', function() {
return console.log('reQ.on end');
});
res.on('close', function() {
return console.log("reS.on close");
});
res.connection.on('close', function() {
return console.log('reS.connection.on close');
});
res.on('end', function() {
return console.log('reS.on end');
});
stream.on('close', function() {
return console.log('stream.on close');
});
return stream.pipe(res);
};
What is the event to listen to ?
note : I am using express, but it should make no difference.
cheers !
Aucun commentaire:
Enregistrer un commentaire