Erlang causes page faults - erlang

When I run the script described here with my user, everything is well:
lorenzo#enzo:~/erlang/pei$ time erl -noshell -smp enabled -S 4 -s fib4 main 10000000
real 0m54.952s
user 1m16.090s
sys 0m0.070s
When I run it as root, it crashed:
lorenzo#enzo:~/erlang/pei$ sudo time erl -noshell -smp enabled -S 4 -s fib4 main 10000000
[sudo] password for lorenzo:
74.68user 0.04system 0:53.56elapsed 139%CPU (0avgtext+0avgdata 66064maxresident)k
0inputs+0outputs (0major+8306minor)pagefaults 0swaps
The error is reproduceable.
My questions are:
Can someone try to explain me what is happending there?
Is it a problem with the erlang runtime or with my OS?
Can someone reproduce this error?
I am running erlang 5.7.4 on ubuntu natty with kernel
Linux enzo 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
on a Phenom X4.

Why do you think it crashed? time just shows more info when running as root. Page fault is not an error but just the way virtual memory works.

The difference between the two runs is that in the first run, you're running the shell builtin time, but in the second run, you're running whatever sudo finds in the path, which is /usr/bin/time. These two tools have different output formats.
$ type time
time is a shell keyword
$ time echo
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ type /usr/bin/time
/usr/bin/time is /usr/bin/time
$ /usr/bin/time echo
0.01user 0.00system 0:00.00elapsed 1000%CPU (0avgtext+0avgdata 2784maxresident)k
0inputs+0outputs (0major+217minor)pagefaults 0swaps

Related

uwsgi upgrade to python3.7 to fix ImportError: No module named 'encodings'

Honestly, I have no idea what I am doing, so be gentle with me. I am trying to use uwsgi to run my django application on a aws ubuntu instance. I have a virtual environment with python3.7 running, but when I try to run uwsgi. I get this in the logs:
*** Starting uWSGI 2.0.14 (64bit) on [Sun Jan 5 14:51:32 2020] ***
compiled with version: 5.4.0 20160609 on 20 October 2016 05:56:34
os: Linux-4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018
nodename: ip-172-31-41-139
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /home/ubuntu/web/graff
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3804
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /home/ubuntu/web/graffuwsgi.sock fd 3
Python version: 3.5.2 (default, Oct 8 2019, 13:06:37) [GCC 5.4.0 20160609]
Set PythonHome to /home/ubuntu/.virtualenvs/graff
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Here is my uwsgi.conf
# file: /etc/init/graffuwsgi.conf
description "uWSGI server for graff"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi --home /home/ubuntu/web/graff/ --socket /home/ubuntu/web/graffuwsgi.sock --chmod-socket=666 --module=graff.wsgi --pythonpath /home/ubuntu/web -H /home/ubuntu/.virtualenvs/graff --logto /home/ubuntu/web/logs/graffuwsgi.log --chdir=/home/ubuntu/web/graff --chmod-socket=666
It seems like python3.5 just doesn't work anymore. I feel like I've had to replace python3.5 with 3.7 in several places lately to fix various bugs, and I have it in my head that if I can get uwsgi to run python3.7 instead of 3.5 then that will solve this error too. Anyway, any help is much appreciated.
Looks like your uwsgi is compiled with different python version, make sure you compile with python 3.5
PYTHON=python3.5 uwsgi --build-plugin "/usr/src/uwsgi/plugins/python python35"
mv python35_plugin.so /usr/lib/uwsgi/plugins/python35_plugin.so
chmod 644 /usr/lib/uwsgi/plugins/python35_plugin.so
you can follow this guide:
https://www.paulox.net/2017/04/04/how-to-use-uwsgi-with-python3-6-in-ubuntu/
The source of error is PythonHome (pyhome, venv, home) setting.
See at the official Python docs on Environment variables
Is your path /home/ubuntu/.virtualenvs/graff suited for Python requirements?
In short:
Use pythonpath (pp) and let the system to find modules.
You can set several repeated options in your uwsgi config to custom modules search, eg:
pythonpath = /opt/web2py/
pythonpath = /opt/anaconda/lib/python3.9/site-packages/
So, I had the same error. And it was fixed by editing uwsgi vassal config.
I thing the core of problem that virtual envs are created with symlinks or have some inner relative paths, so an isolated process inside uwsgi could not find modules.

ejabber's erl file give error "segmentation fault: 11" while running on mac os 10.7.5

I am trying to start ejabber 16.05 server on mac os 10.7.5. while starting up, it gives error. on further investigation, I found that "erl" executor file shipped with ejabber is throwing "Segmentation Fault:11" while running independently. I firmly believe that resolving issue with "erl" file execution will solve server start up issue. can anyone please help. Below is the code from "erl" that is causing segmentation fault error
#!/bin/sh
ROOTDIR=/Applications/ejabberd-15.06
export ROOTDIR
BINDIR=$ROOTDIR/bin
export BINDIR
EMU=beam
export EMU
PROGNAME=$BINDIR/erl
export PROGNAME
PATH=$BINDIR:$PATH
export PATH
arch() {
case `uname -m` in
i[3456]86 ) echo x86 ;;
i86pc) echo x86 ;;
armv7*) echo armhf ;;
arm*l) echo armel ;;
* ) echo `uname -m | tr A-Z a-z` ;;
esac
}
os=`uname -s | tr A-Z a-z`
cpu=`arch`
ARCHDIR=${os}-${cpu}
export ARCHDIR
# Dynamic libraries
LD_LIBRARY_PATH=$ROOTDIR/lib/$ARCHDIR
export LD_LIBRARY_PATH
DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
exec $BINDIR/erlexec ${1+"$#"}
I just see that you are using OSX 10.7. We do not test ejabberd binary installer on version of OS that are so old.
I do not even expect the binary installer to run on such an old release.
If you have to run ejabberd on that OSX version, you have to build it from source.
ejabberd source are available on official ejabberd Github.
Documentation for installation and build is here Installing ejabberd from source code.

erlang R16B01 and Windows CMD

I'm windows 7 user and try to learn erlang and here's the time when I get to the paragraph where I have to deal with creating and naming nodes. I used to start erlang emulator from shortcut and don't know how to start it from command prompt window to use -name or -sname commands, and when I try to use
net_kernel:start([node,shortnames]).
command I get
{error,
{{shutdown,
{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}},
{child,undefined,net_sup_dynamic,
{erl_distribution,start_link,[[node,shortnames]]},
permanent,1000,supervisor,
[erl_distribution]}}}
=INFO REPORT==== 23-Aug-2013::15:28:03 ===
Protocol: "inet_tcp": register/listen error: econnrefused
error. I thought it was because of windows firewall and turned it off, but nothing has changed. So can someone answer what's going on?? And if you don't mind teach me how can I start erlang from CMD and use -name and -sname commands.
1) make sure you have in the path, program files \ erlang \ bin \ erl
2) open the command prompt and type
3) erl -sname dilbert
-name = for fully qualified name [dilbert#mypc.maydomain.com]
-sname for short name [dilbert#mypc]
this will give you
% erl -sname dilbert
(dilbert#mypc)1> node().
dilbert#mypc
I am, most of the time, a windows user, and as it is not natural in this environment to use command windows, I used to write some command files to invoke werl (the usual VM interface in windows). But I stopped that, because it is less convenient and less flexible than the command window, and also because I very often need other command line tools like ping, ipconfig, or git...
I join an example of the code you can use:
launch_werl.bat:
echo off
echo Select a project:
echo 1: project 1
echo 2: project 2
echo 3: project 3
set /p proj=
goto label%proj%
:label1
d:
cd "\git\project1"
set prname=proj1
goto end
:label2
d:
cd "\documents and Settings\user\My Documents\path\to\some\code"
set prname=proj2
goto end
:label3
d:
cd "\git\proj3"
set prname=PLC
goto end
:end
start werl -sname %prname% -pa "./ebin"
echo on

luajit2.0.0 -- Segmentation fault: 11

I use a simple example from http://lua-users.org/wiki/SimpleLuaApiExample to make a test. The sample can be statically linked with libluajit.a with a success, but this error message occurs when you run it:
Segmentation fault: 11
I use LuaJIT-2.0.0 released at 2012-11-08. My OS is Mac OSX Lion 10.7.5.
$ uname -a
Darwin macmatoMacBook-Pro.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
The test steps:
compile luajit-2.0.0
$ cd lj2
$ ls
COPYRIGHT Makefile README doc dynasm etc src
$ make
==== Building LuaJIT 2.0.0 ====
make -C src
DYNLINK libluajit.so
LINK luajit
OK Successfully built LuaJIT
==== Successfully built LuaJIT 2.0.0 ====
$ rm src/*.so # force to use the static version: libluajit.a
$ cd ..
compile and run the sample app
Both test.c and script.lua come from here. The folder lj2 contains the source code of the above luajit-2.0.0, just compiled successfully.
$ ls
lj2 script.lua test.c
use clang compiler
$ clang -o test test.c -I./lj2/src -L./lj2/src -lluajit
$ ./test
Segmentation fault: 11
use gcc compiler
$ gcc -o test test.c -I./lj2/src -L./lj2/src -lluajit
$ ./test
Segmentation fault: 11
But if I replace lj2/src/luajit.c with test.c, it will give me a success. This is very strange. See below:
$ cd lj2
$ make clean
$ mv src/luajit.c src/luajit.c.orig
$ cp ../test.c src/luajit.c
$ make
$ cp src/luajit ../
$ cd ..
$ ./luajit
The table the script received has:
1 2
2 4
3 6
4 8
5 10
Returning data back to C
Script returned: 30
Problem resolved. There is an section which explains how to Embedding LuaJIT in this page:
http://luajit.org/install.html
If you're building a 64 bit application on OSX which links directly or indirectly against > LuaJIT, you need to link your main executable with these flags:
-pagezero_size 10000 -image_base 100000000
Also, it's recommended to rebase all (self-compiled) shared libraries which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua). See: man rebase
Now, let me test it again:
$ clang -o test test.c -O3 -I./lj2/src -L./lj2/src -lluajit -pagezero_size 10000 -image_base 100000000
$ ./test
The table the script received has:
1 2
2 4
3 6
4 8
5 10
Returning data back to C
Script returned: 30
And valgrind returns
$ valgrind ./test
bad executable (__PAGEZERO is not 4 GB)
valgrind: ./test: cannot execute binary file
That's another question.

Can "cap deploy:setup" destroy BASH?

I had a problem this morning deploying an application with capistrano.
# git push
# cap deploy:setup
Something strange happened and than I wasn't able to ssh to my host anymore.
Technical staff says (in Italian): "the commands you have run overwrote the shell binaries causing the system to be no more usable". Two options: I am a stupid, or they are wrong.
Here's the shell output on cap:deploy and then the error on ssh. Once the system (VPS) has been rebooted, I wasn't able to ssh anymore.
Any ideas?
mattia#desktop:/var/www/rails/my_application$ git push
Counting objects: 239, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (191/191), done.
Writing objects: 100% (202/202), 379.77 KiB, done.
Total 202 (delta 44), reused 0 (delta 0)
To ssh://mattia#my_application.it/~/git/my_application.git
96c1f19..3cc9e1c master -> master
mattia#desktop:/var/www/rails/my_application$ cap deploy:setup
* executing `deploy:setup'
* executing "mkdir -p /var/www/rails/my_application /var/www/rails/my_application/releases /var/www/rails/my_application/shared /var/www/rails/my_application/shared/system /var/www/rails/my_application/shared/log /var/www/rails/my_application/shared/pids && chmod g+w /var/www/rails/my_application /var/www/rails/my_application/releases /var/www/rails/my_application/shared /var/www/rails/my_application/shared/system /var/www/rails/my_application/shared/log /var/www/rails/my_application/shared/pids"
servers: ["beta.my_application.it"]
[beta.my_application.it] executing command
** [out :: beta.my_application.it]
** [out :: beta.my_application.it] malloc: ../bash/parse.y:2823: assertion botched
** [out :: beta.my_application.it] nunits < 30
** [out :: beta.my_application.it] Aborting...
command finished
failed: "env PATH=/usr/local/bin:/usr/bin:/bin GEM_PATH=/var/lib/gems/1.9.1 sh -c 'mkdir -p /var/www/rails/my_application /var/www/rails/my_application/releases /var/www/rails/my_application/shared /var/www/rails/my_application/shared/system /var/www/rails/my_application/shared/log /var/www/rails/my_application/shared/pids && chmod g+w /var/www/rails/my_application /var/www/rails/my_application/releases /var/www/rails/my_application/shared /var/www/rails/my_application/shared/system /var/www/rails/my_application/shared/log /var/www/rails/my_application/shared/pids'" on beta.my_application.it
mattia#desktop:/var/www/rails/my_application$ ssh beta.my_application.it
Linux my_application 2.6.18-194.26.1.el5.028stab079.2ent #1 SMP Fri Dec 17 19:44:51 MSK 2010 i686
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Feb 7 12:00:53 2011 from dynamic-adsl-xx-xx-xx-xx.------.------.it
malloc: ../bash/subst.c:4494: assertion botched
realloc: called with unallocated block argument
Aborting...Connection to beta.my_application.it closed.
The short-answer is no, unless you have other plugins that aren't standard, or someone gave you a messed up Gem. (Almost nobody bothers to validate the gem signatures.) The standard deploy:setup only creates a couple of symlinks, and directories.
It does run as root, and in theory if you were to set your variables to values (untested) such as set :deploy_to, '/bin/bash', it may damage the binary, but unless you did that, I'd say that's a non-issue.
You can debug this, without relying on a shell - by using SSH in command mode:
# ssh myuser#myserver -c 'history'
Which will dump out the history file (bash) of that user, so you can test if there's been any tampering on the server, you can also check it as root, and/or run commands such as who, last and other one-liners which give you back logs (you can also cat /var/log/messages and look for suspicious activity.
I'd say that the chance of Capistrano being responsible for this is 0 (Source: I'm the maintainer.) - but you can probably get your system back into a working state using the SHS command mode, as I mentioned above (ssh myuser#myserver -c 'aptitude install bash --force' for example)
A word to the wise, if you never figure out how this happened, erase the server and change your passwords… just use this as a method to get things back up and running. It's not a very subtle tactic, but if you've been hacked, a hacker could easily throw you out by making a user which uses an alternative shell, and corrupting yours.
It would also be a huge help from your admins, if they could give you /bin/bash - the contents of the file, so you can see if it's text, junk, corrupted binary, or something from your deploy.

Resources