You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
In order to prevent excessive memory usage, Domain objects themselves are not implicitly added as children of the active domain. If they were, then it would be too easy to prevent request and response objects from being properly garbage collected.
If you want to nest Domain objects as children of a parent Domain, then you must explicitly add them, and then dispose of them later.
Is it ok if I do the following or I'll produce memory leaks?
vardomain=require("domain");varhttp=require("http");vard=domain.create();d.on("error",function(error){console.error(error);});d.run(function(){http.createServer(function(req,res){vardreq=domain.create();dreq.add(req);dreq.add(res);dreq.on("error",function(error){//The null.error is handled hereres.writeHead(500);res.end();console.error(error);dreq.exit();});dreq.run(function(){null.error});}).listen(1337,"localhost");});
Thanks
The text was updated successfully, but these errors were encountered:
That should work and it won't create memory leaks.
It's IMO not a very safe or scalable approach, though. In a non-trivial application, how will you know when it's safe to use the response object in the domain's error handler? If the error was generated by the response object, boom! - you're dead.
In the future, please direct questions to the mailing or IRC. The bug tracker is not really the place for it.
I want to send to the user a response when an error occurs but I don't have any reference to the response object inside the error handler:
The docs are a bit confusing to me:
Is it ok if I do the following or I'll produce memory leaks?
Thanks
The text was updated successfully, but these errors were encountered: