crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.45k stars 1.62k forks source link

Running shards works for root, not for normal user #6965

Closed rodti closed 6 years ago

rodti commented 6 years ago

Clean install of Crystal (via aptitude) on Debian 9, running in a Proxmox LXC container.

Running shards as root gives expected results:

Missing shard.yml. Please run 'shards init'

Running shards for any other normal user account (without sudo) crashes:

Failed to raise an exception: END_OF_STACK
[0x7f70dc3d6826] ???
[0x7f70dc37a8a3] ???
[0x7f70dc37b4b8] ???
[0x7f70dc37d6d3] ???
[0x7f70dc39e8c2] ???
[0x7f70dc37c8fd] ???
[0x7f70dc6239a5] ???

I also get a crash running crystal as a normal user. I've tried this with several new user accounts, all have the same issue.

Also, out of abundance of caution, I've tried this on both unprivileged and privileged LXC containers, with identical results.

refi64 commented 6 years ago

I've also noticed this under rootless podman containers.

j8r commented 6 years ago

This issue isn't related to Crystal itself, but the shards package manager. Please open the issue in this project: https://github.com/crystal-lang/crystal/shards

straight-shoota commented 6 years ago

I also get a crash running crystal as a normal user.

Doesn't look like it's specific to shards.

And Failed to raise an exception: END_OF_STACK doesn't either.

ysbaddaden commented 6 years ago

I use LXC containers everyday, and never had such an issue. I would easily blame systemd, maybe.

j8r commented 6 years ago

@rodti are you sure you have read/write permissions on the directories used by shards? I got this as a normal user in /srv:

Unhandled exception: Error opening file '/srv/shard.yml' with mode 'w': Permission denied (Errno)
Failed to raise an exception: END_OF_STACK
[0x557996f25c56] *CallStack::print_backtrace:Int32 +118
[0x557996f08b46] __crystal_raise +86
[0x557996f090ee] *raise<Errno>:NoReturn +206
[0x557996f5b3d9] *Crystal::System::File::open<String, String, File::Permissions>:Int32 +201
[0x557996f50a0d] *File::new<String, String, File::Permissions, Nil, Nil>:File +45
[0x557996f1d3dd] *CallStack::read_dwarf_sections:(Array(Tuple(UInt64, UInt64, String)) | Nil) +109
[0x557996f1d11d] *CallStack::decode_line_number<UInt64>:Tuple(String | Nil, Int32, Int32) +45
[0x557996f1c8c8] *CallStack#decode_backtrace:Array(String) +296
[0x557996f1c782] *CallStack#printable_backtrace:Array(String)+ +50
[0x557996f5063d] *Exception+ +77
[0x557996f50088] *Exception+ +120
[0x557996fa0978] *AtExitHandlers::run<Int32>:Int32 +488
[0x557996f85654] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +148
[0x557996f13816] main +6
[0x7f2aaa8ccad6] __libc_start_main +54

I got this by compiling shards statically with crystal build --static --link-flags -lunwind src/shards.cr:

Failed to raise an exception: END_OF_STACK
[0x0] ???
rodti commented 6 years ago

Hi everyone, apologies for the delay in replying.

I've created a brand new LXC container on a different Proxmox (pve 5.2-2) host. This uses a Debian 9.3.1 image.

I've run apt-get dist-upgrade to ensure everything's up to date, added apt-transport-https, then followed the instructions for Debian/Ubuntu to add Crystal's aptitude source. I've install using apt install crystalwhich completes successfully with all dependencies.

I then ran adduser testto create a 'test' user.

Running crystal as root in /root gives:

Usage: crystal [command] [switches] [program file] [--] [arguments]

Command:
    init                     generate a new project
    build                    build an executable
    docs                     generate documentation
    env                      print Crystal environment information
    eval                     eval code from args or standard input
    play                     starts crystal playground server
    run (default)            build and run program
    spec                     build and run specs (in spec directory)
    tool                     run a tool
    help, --help, -h         show this help
    version, --version, -v   show version

Running shards as root in /root gives:

Missing shard.yml. Please run 'shards init'

Running crystalas test in /home/test gives:

Failed to raise an exception: END_OF_STACK
[0x7fed6d889746] ???
[0x7fed6cf82349] ???
[0x7fed6cf83488] ???
[0x7fed6cf882a3] ???
[0x7fed6cfbb3f6] ???
[0x7fed6cf8679d] ???
[0x7fed6ecc8dfe] ???

Running shards as test in /home/test gives:

Failed to raise an exception: END_OF_STACK
[0x7f6f4dd6e826] ???
[0x7f6f4dd128a3] ???
[0x7f6f4dd134b8] ???
[0x7f6f4dd156d3] ???
[0x7f6f4dd368c2] ???
[0x7f6f4dd148fd] ???
[0x7f6f4dfbb9a5] ???

Happy to share any logs if required.

ysbaddaden commented 6 years ago

Your container is restricting access to something that Crystal depends on (e.g. a file from /dev or proc).

You can use strace crystal to understand where it's failing. For example, these paths will be open by crystal or a dependency (bdwgc, libevent, ...):

rodti commented 6 years ago

Your container is restricting access to something that Crystal depends on (e.g. a file from /dev or proc).

Thanks for the tip. I've run strace and it was failing on /dev/tty1 access. I've changed the permissions on /dev/tty1 to a fairly loose 777 and it now works correctly.

Odd that it needs a workaround though!

ysbaddaden commented 6 years ago

Related to #6518

rodti commented 6 years ago

When I went to apply the fix to the container where I noticed this issue it was /dev/pts3 rather than /dev/tty1, but adding the user to group tty and setting permissions to 660 worked. I'm assuming this is a peculiarity of LXC and not Crystal, so will close this issue.

RX14 commented 6 years ago

Duplicate of #6624

Fixed by https://github.com/crystal-lang/crystal/pull/6660 most likely.