cosmopolitan icon indicating copy to clipboard operation
cosmopolitan copied to clipboard

Redbean demo 2.2 crashes with docker alpine:latest

Open devx-opensource opened this issue 2 years ago • 2 comments

Hello,

The demo 2.1 works with the Dockerfile below but not 2.2. I'm using docker on a macbook pro m2.

Dockerfile (just replace 2.2 by 2.1 to get the demo working):

FROM alpine:latest

RUN apk add --update bash
RUN wget https://redbean.dev/redbean-demo-2.2.com -O demo
RUN chmod +x demo
RUN /demo --assimilate

CMD ["/demo", "-vv", "-p", "80"]

Crash report:

tool/net/redbean.c:4997:demo:1] (lua) LuaRunAsset("/.init.lua")

Uncaught SIGILL (ILL_ILLOPN) on 3462bb5bb52c pid 1 tid 1
  /demo
  EFAULT/14/Bad address
  Linux #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 3462bb5bb52c 5.15.49-linuxkit-pr

RAX ffffffffffffffff RBX 00000000000001b6 RDI 0000000000000002 ST(0) 0.0
RCX 000000000000000e RDX 000070000003eb00 RSI 000070000003eb40 ST(1) 0.0
RBP 000070000003eb60 RSP 000070000003eb40 RIP 000000000058d159 ST(2) 0.0
 R8 0000000000000000  R9 0000000068746170 R10 0000000000000008 ST(3) 0.0
R11 0000000000000002 R12 0000000000000000 R13 00000000ffffff9c ST(4) 0.0
R14 000070000003ed50 R15 000070000003ec08

XMM0  00000000000000000000000000000000 XMM8  00000001c6e415960000000154442bd4
XMM1  00000000000000000000000000000000 XMM9  74636e754a7f1e2ac08b24992e70c36b
XMM2  3b3b3b3b3b3b3b3b3b3b3b3b3b3b3b3b XMM10 00000000000000000000000000000000
XMM3  00000000000000000000000000000000 XMM11 00000000000000000000000000000000
XMM4  00001000800a774000001000800b1044 XMM12 00000000000000000000000000000000
XMM5  010300440903012e03020125000001ce XMM13 00000000000000000000000000000000
XMM6  0300000b7fffff3800007fc302020044 XMM14 00000000000000000000000000000000
XMM7  000100830100000b010100440000000b XMM15 00000000000000000000000000000000

10008007f3a0 58d159 _sigsetmask+73
70000003eb60 58cd93 _sigblockall+35
70000003eb80 5620c4 __zipos_open+36
70000003ebf0 589ecd openat+171
70000003ec90 589e20 open+61
70000003ecf0 565c71 fopen+97
70000003ed20 4d91d0 searchpath+240
70000003f5a0 4d9954 findfile.constprop.0+84
70000003f5d0 4d99ac searcher_Lua+44
70000003f5f0 4d24a5 luaD_precall+405
70000003f650 4d2622 ccall+50
70000003f680 4d2763 luaD_callnoyield+19
70000003f690 4ccc86 lua_callk+70
70000003f6b0 4d8ea4 findloader+180
70000003fb00 4d8ff8 ll_require+136
70000003fb20 4d24a5 luaD_precall+405
70000003fb80 4ec6da luaV_execute+1434
70000003fc50 4d263b ccall+75
70000003fc80 4d26ad resume+61
70000003fcb0 4d1834 luaD_rawrunprotected+84
70000003fd30 4d27f2 lua_resume+130
70000003fd60 4e7adf LuaCallWithTrace+431
70000003fdc0 423efe LuaRunAsset+286
70000003fe20 42eb8b RedBean+2251
70000003ffc0 402acd main+45
70000003ffe0 4030c9 cosmo+77
004000800dc0 402504 _start+130

10008004-10008008 rw-pa-  5x automap 320kB
10008009-10008009 rw-sa-  1x automap 64kB
1000800a-1000800c rw-pa-  3x automap 192kB w/ 192kB hole
10008010-10008014 rw-pa-  5x automap 320kB w/ 2688kB hole
1000803f-10008043 r--s--  5x automap 317kB w/ 1792kB hole
10008060-10008083 r--p-- 36x automap 2301kB w/ 96tB hole
6fc00004-6fc00014 rw-paF 17x kmalloc 1088kB w/ 64gB hole
6fd00004-6fd00004 rw-paF  1x zipos 64kB w/ 64gB hole
6fe00004-6fe00004 rw-paF  1x g_fds 64kB
70000000-70000003 rw-Sa-  4x stack 256kB
# 4992kB total mapped memory
/demo -vv -p 80 

PS: I'm trying to host a redbean server on the fly.io platform for anyone wondering why I'm using docker.

devx-opensource avatar Jun 25 '23 20:06 devx-opensource

In case it helps, this Dockerfile worked for me on fly.io:

FROM alpine:latest as build

ARG DOWNLOAD_FILENAME=redbean-unsecure-2.2.com

RUN apk add --update bash zip
RUN wget https://redbean.dev/${DOWNLOAD_FILENAME} -O redbean.com
RUN chmod +x redbean.com

RUN sh ./redbean.com --assimilate

FROM scratch

COPY --from=build ./redbean.com .
CMD ["./redbean.com"]

I'm using redbean-unsecure-2.2.com here because fly.io is terminating https. redbean-2.2.com should work too, it just has a little unnecessary baggage.

Don't use redbean-demo-2.2.com, though, unless you modify .init.lua first:

https://github.com/jart/cosmopolitan/blob/18536950b3db37da45641bc5805d82ea6056d283/tool/net/demo/.init.lua#L5

https://github.com/jart/cosmopolitan/blob/18536950b3db37da45641bc5805d82ea6056d283/tool/net/demo/.init.lua#L12

The first requires some additional setup, and the second can't work in Docker.

michaellenaghan avatar Jul 20 '23 20:07 michaellenaghan

Btw, redbean uses just ~36MB on fly.io, and in light testing I haven't been able to get the average load above 0.

(That's total memory usage. I also tried redbean on a shared host that charges in terms of resource usage. They say that redbean-unsecure-2.2.com uses ~3MB. By contrast, my PHP apps on that same host use ~35MB.)

michaellenaghan avatar Jul 20 '23 20:07 michaellenaghan