Fatal error in V8 - javascript

I'm trying to deploy my Rails app to a new VPS which runs with Debian. I'm using Nginx and Phusion Passenger as my server.
I've installed Node.js as a JavaScript runtime. Sadly I'm seeing the following error message:
Fatal error in v8::V8::AddGCPrologueCallback()
V8 is no longer usable
Edit:
It is fixed now. Apparently gr security was causing the error.

The Problem occurs on kernels with grsecurity and certain restrictive rules.
node.js needs to exec code in certain areas of memory,where the server does not like it.
You seem to need to switch two flags for the "node" binary.
Also you might need to switch those for your ruby binary.
Toggle SEGMEXEC on
paxctl -S `which node` && paxctl -S `which ruby`
Toggle MPROTECT off
paxctl -m `which node` && paxctl -m `which ruby`
Test if node works now
node -e "console.log(1+1);"
Fun fact is that i can now Toggle SEGMEXEC off and node still works :S... however switching it on seemed to initially fix it for me.
If it does not work, play with the flags and try the node -e
Good luck!
gizmore

Related

How to restart a Node.js project?

I'm not a Node.js developer. So I have no idea how it works. I've been a PHP developer for over 8 years.
Because of some reason, I need to make a small change in a Node.js project which is live. All I have to do is changing a payment gateway token. I did it like this:
After pulling it on the server, users still go to the old payment gateway. So I guess I need to do a restart. (I'm saying so because, for PHP projects, when you change a config-related thing, you need to restart PHP).
Not sure should I restart what thing? Noted that, the server is Ubuntu 20.04 and uses Nginx to talk to Node.js. In other word, how can I see Node is running as what service on Linux?
Also, there are two files that I think I need to run the project again after restarting Node through one of them: index.js, server.js. Am I right?
And
Your Node.js script likely runs under a process that restarts the script in case it dies. There are several "run forever" wrappers, the most popular one is pm2. Find out which one is used in your project. Try pm2 list as the user your project executes under. If pm2 type pm2 restart app_name to restart your project.
Please check if it is a node.js project so you can write the command node index.js or node server.js with this command you can start your node server.

HTTP Parse Error in Nodejs when running in a Docker Container

I have a Nestjs Application which I try to run in a docker container. It all worked fine just until recently where I get the error Parse Error: Missing expected CR after header value. I'm trying to make a http GET Request to a webserver of an IoT device. Furthermore this error occurs only when I run the server-app inside a docker container. When I run it locally on a windows or macos machine everything works fine.
I tried using different versions of nodejs in docker. 14, 16 and 18. This error always comes up, independent of which version I use. I have no idea how I could debug this error, since it only occurs when I serve the app inside a docker container.
This is my dockerfile:
FROM node:slim
RUN mkdir -p /app
WORKDIR /app
COPY src .
COPY package.json .
RUN apt update && apt install python3 make g++ -y
RUN npm install --force
EXPOSE 3000
CMD ["npm", "run", "start:dev"]
According to this issue, this was recently implemented in Node v14.20.0, v16.16.0 and v18.5.0. Apparently it fixes a vulnerability in the HTTP parser of earlier versions.
Comments below the issue suggest various workarounds if it's not possible to fix the client, the easiest of which seems to be to set the insecureHTTPParser flag to true when creating the HTTP server.
Alternatively, revert to an older minor version of each of the Node.js versions mentioned above.

Bot shuts down when putty window is closed

I created a discord bot and am now attempting to run it off an Ubuntu Machine.
I installed the folders of the bot and NodeJs, here is what I used to install NodeJS:
sudo apt-get install -y nodejs
Then I used cd to select the directory, and started my bot using node index.js
The bot started, however when I went to close the putty and keep it running on the VPS the bot shutdown. Here is what the directory looks like.
I think the problem is that when you start the app in the putty window, that process is linked to the window and gets terminated when that is closed.
To avoid that you can use a host service like screen, tmux, nohup, bg and so on...
If you want to know which is the best, try looking at this question from the askUbuntu Stack Exchange.
The key concept is that you open a new window using the tmux command (or screen, ...), then run your bot like you always do. When you want to leave but keep the process runing, you can detach the session with a key combination, that changes from service to service.
If you want to access that window again, you can run a command that will "restore" your session, like
tmux list-sessions
tmux attach-session -t 0
The NodeJS instance is terminated when putty is closed. You need something to keep the instance alive. Try:
PM2: http://pm2.keymetrics.io/
or,
Forever: https://github.com/foreverjs/forever#readme
Recommended though is to run the node instance as a service that can reboot on startup. Try looking at this:
https://stackoverflow.com/a/29042953/7739392
The shell runs in the foreground. This means any scripts you start there will end once you end your session. A simple solution would be to run your script in the background by adding the & after the call:
node index.js &
A better solution would be to create a service you can ask the service daemon to run for you. However, adding the & should get you what you want for now.
I recommend using one of these two node modules - ForeverJS or PM2. I'll show you how to quickly get started with ForeverJS but PM2 would be very similar.
You can easily install ForeverJS by typing the following in your terminal:
$ npm install forever -g
You may need to use SUDO depending on your user's privileges to get this working properly. It is NOT recommended to use it in production due to the security risks.
Once installed CD to your projects file directory and like you typed 'node index.js' you will do something similar with ForeverJS.
$ forever start index.js
Now when you exit the terminal your NodeJS application will remain as a running process.

FreeSwitch mod installation fails

I have installed FreeSwitch on mac (OS X Yosemite 10.10.5) and I have to use javascript (mod_v8) for IVR calls. I have followed the steps for mod_v8 activation here: https://freeswitch.org/confluence/display/FREESWITCH/mod_v8
1.Uncomment languages/mod_v8 in modules.conf in your src directory (make it always build and install mod_v8)
2.Run 'make mod_v8-install' to make and install just the v8 module
3.Edit conf/autoload_configs/modules.conf.xml in your FreeSWITCHâ„¢ install directory to load mod_v8
4.In fs_cli, run "load mod_v8"*
However, I get the following error while running make mod_v8-install (Step 2) :
error on terminal
Also should I disable LUA when activating mod_v8?
This seems to be a 'info' type error being generated by the compiler.. Report the issue as a bug to FreeSWITCH?
Or try using the -i flag when compiling - https://www.gnu.org/software/make/manual/html_node/Errors.html
"Also should I disable LUA when activating mod_v8?"
No :)
Uncomment the from modules.conf.xml after recompiling. Try "reload mod_v8" command in fs_cli. I had the same issue its missing in the freeswitch document.

PhantomJS gives Segmentation fault when running any js using command line

I have installed Phantomjs 1.9.8 on my Centos 6.5 server.
From the command line if I type
phantomjs -v
I get the correct version number returned, so I presume that it is installed ok.
However if I create a simple javascript file, using the most basic example from the phantomjs example:
console.log('Hello, world!');
phantom.exit();
and save this to a file test.js, navigate to that folder via command line and run
phatomjs test.js
I get
PhatomJS has crashed... Segmentation fault.
Any idea what could be causing this or further tests I could run?
A simple solution - A key step of course is that you have to restart your apache web server to get this to work, I had forgotten this.
Leaving this up in case it helps anyone else stumbling along the same route

Categories