ignacio / LuaNode

Asynchronous I/O for Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

os.exit() crashes

Tieske opened this issue · comments

trying to exit LuaNode with os.exit() but it hangs when executing that (from the REPL)

The proper way to exit from LuaNode is to call process:exit([exit_code]). It calls registered handlers for the exit event, stops the event loop, closes the Lua vm, performs some cleanup and then calls exit.

On the other hand, os.exit() just calls exit. It's a shortcut, for those cases in which you reach an error condition and need to get out of there ASAP. No cleanup, just leave. The thing is that, under certain circumstances, exiting without stopping the event loop makes it hang.

Thx for the info. I can live with that, but... I still think that the hang should be fixed, if you want to exit, exit, but not hang. It defeats the purpose.

Well, yes. I agree with you. But os.exit() just pulls the rug, and that is something that Asio (the library that implements the event loop) is not happy with. Bear in mind though that it tends to hang when using the repl, but if you run this script from a file, it exits without hanging.

console.log("foo")
os.exit()
console.log("bar") -- does not reach this line

Eventually, I'll try to figure out if there is a way to get Asio to not hang.