javascript - Why would an exception cause resource leaks in Node.js? -
if @ beginning of node.js documentation domains states:
by nature of how throw works in javascript, there never way safely "pick left off", without leaking references, or creating other sort of undefined brittle state.
again in code example gives in first section says:
though we've prevented abrupt process restarting, leaking resources crazy
i understand why case? resources leaking? recommend use domains catch errors , safely shutdown process. problem exceptions, not when working domains? bad practice throw , catch exceptions in javascript? know it's common pattern in python.
edit
i can understand why there resource leaks in non garbage collected language if throw exception because code might run clean objects wouldn't run if exception thrown.
the reason can imagine javascript if throwing exception stores references variables in scope exception thrown (and maybe things in call stack), keeping references around, , exception object kept around , never gets cleaned up. unless leaking resources referred resources internal engine.
update
i've written blog explaining answer bit better now. check out
unexpected exceptions ones need worry about. if don't know enough state of app add handling particular exception , manage necessary state cleanup, definition, state of app undefined, , unknowable, , it's quite possible there things hanging around shouldn't be. it's not memory leaks have worry about. unknown application state can cause unpredictable , unwanted application behavior (like delivering output that's wrong -- partially rendered template, or incomplete calculation result, or worse, condition every subsequent output wrong). that's why it's important exit process when unhandled exception occurs. gives app chance repair itself.
exceptions happen, , that's fine. embrace it. shut down process , use forever detect , set things on track. clusters , domains great, too. text reading not caution against throwing exceptions, or continuing process when you've handled exception expecting -- it's caution against keeping process running when unexpected exceptions occur.
Comments
Post a Comment