I\'ve been working on a deployment work flow with Dokku and Docker and now I want to take care of continuity of my app (along the lines of Forever). To test it, I need a way
Three things come to my mind:
while (true) {}
. This should make Node.js use 100% of your CPU, and hence the application should be restarted as well (although this, of course, means that you / someone has to watch your application).To add to Golo answer:
C module to crash by segmentation fault:
int main ()
{
//Create a array of 1 char
char a [1];
//Create a index
int i = 0;
//Infinite loop to go around the compiler
while(1)
{
//Write on case i of a, on the second iteration, it will write in unreserved memory => crash
a[i] = 0;
i = i + 1;
}
//Should not go there
return -1;
}
And adding to DrakaSAN's answer, an even simpler C module to crash:
int main()
{
*(int*)(0) = 0;
return -1;
}
Even shorter ones are available on this page. If you don't want it to be too hard to read, you can probably go with
int main()
{
int i=1/0;
}
I was attempting a similar thing with a /crash route in express, but just throwing an error from within the route handler was not enough to crash it.
process.exit would stop my app but forever would not restart it. (The forever logs just said something like process self terminated.)
What did work for me was inserting this into my /crash
route:
setTimeout(function () {
throw new Error('We crashed!!!!!');
}, 10);