xcaddy build: fatal error: runtime: out of memory

This issue has been created since 2021-03-11.

Following this guide, I'm attempting to install caddy on ubuntu server 18.04.

The build fails with fatal error: runtime: out of memory

This is the build output when running xcaddy build.

2021/03/11 10:21:30 [INFO] Temporary folder: /tmp/buildenv_2021-03-11-1021.749880544
2021/03/11 10:21:30 [INFO] Writing main module: /tmp/buildenv_2021-03-11-1021.749880544/main.go
2021/03/11 10:21:30 [INFO] Initializing Go module
2021/03/11 10:21:30 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy
go: creating new go.mod: module caddy
go: to add module requirements and sums:
        go mod tidy
2021/03/11 10:21:30 [INFO] Pinning versions
2021/03/11 10:21:30 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2
go get: added github.com/caddyserver/caddy/v2 v2.3.0
2021/03/11 10:21:36 [INFO] Build environment ready
2021/03/11 10:21:36 [INFO] Building Caddy
2021/03/11 10:21:36 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy
2021/03/11 10:21:39 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /home/test_user/caddy/caddy -ldflags -w -s -trimpath
# github.com/yuin/goldmark/util
fatal error: runtime: out of memory

runtime stack:
runtime.throw(0xcac687, 0x16)
        /usr/local/go/src/runtime/panic.go:1117 +0x72
runtime.sysMap(0xc010000000, 0x4000000, 0x11e7b90)
        /usr/local/go/src/runtime/mem_linux.go:169 +0xc6
runtime.(*mheap).sysAlloc(0x11c8bc0, 0x400000, 0x42bcf7, 0x11c8bc8)
        /usr/local/go/src/runtime/malloc.go:729 +0x1e5
runtime.(*mheap).grow(0x11c8bc0, 0x20, 0x0)
        /usr/local/go/src/runtime/mheap.go:1346 +0x85
runtime.(*mheap).allocSpan(0x11c8bc0, 0x20, 0x460000, 0x7fcaf6837928)
        /usr/local/go/src/runtime/mheap.go:1173 +0x609
        /usr/local/go/src/runtime/mheap.go:910 +0x59
        /usr/local/go/src/runtime/asm_amd64.s:379 +0x66

goroutine 1 [running]:
        /usr/local/go/src/runtime/asm_amd64.s:339 fp=0xc00aa33468 sp=0xc00aa33460 pc=0x46d460
runtime.(*mheap).alloc(0x11c8bc0, 0x20, 0x200100, 0x203003)
        /usr/local/go/src/runtime/mheap.go:904 +0x85 fp=0xc00aa334b8 sp=0xc00aa33468 pc=0x4279a5
runtime.(*mcache).allocLarge(0x7fcb1d9fd108, 0x3e590, 0x30001, 0xc8e5e0)
        /usr/local/go/src/runtime/mcache.go:224 +0x97 fp=0xc00aa33510 sp=0xc00aa334b8 pc=0x418017
runtime.mallocgc(0x3e590, 0xc8e5e0, 0xcc8b01, 0x1)
        /usr/local/go/src/runtime/malloc.go:1078 +0x925 fp=0xc00aa33598 sp=0xc00aa33510 pc=0x40de65
runtime.makeslice(0xc8e5e0, 0x7cb2, 0x7cb2, 0xc0051070e8)
        /usr/local/go/src/runtime/slice.go:98 +0x6c fp=0xc00aa335c8 sp=0xc00aa33598 pc=0x44faec
cmd/compile/internal/ssa.fuseBlockPlain(0xc005106dc0, 0xc0029c0d00)
        /usr/local/go/src/cmd/compile/internal/ssa/fuse.go:209 +0x4bf fp=0xc00aa33668 sp=0xc00aa335c8 pc=0x688ebf
cmd/compile/internal/ssa.fuse(0xc0018ce2c0, 0x118469aa82505)
        /usr/local/go/src/cmd/compile/internal/ssa/fuse.go:40 +0xb3 fp=0xc00aa336a0 sp=0xc00aa33668 pc=0x6880f3
        /usr/local/go/src/cmd/compile/internal/ssa/fuse.go:12 +0x30 fp=0xc00aa336c0 sp=0xc00aa336a0 pc=0x687fb0
        /usr/local/go/src/cmd/compile/internal/ssa/compile.go:96 +0x98d fp=0xc00aa37388 sp=0xc00aa336c0 pc=0x66086d
cmd/compile/internal/gc.buildssa(0xc000f358c0, 0x0, 0x0)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:470 +0x11ba fp=0xc00aa375b0 sp=0xc00aa37388 pc=0xb0bc5a
cmd/compile/internal/gc.compileSSA(0xc000f358c0, 0x0)
        /usr/local/go/src/cmd/compile/internal/gc/pgen.go:319 +0x5d fp=0xc00aa37690 sp=0xc00aa375b0 pc=0xad733d
        /usr/local/go/src/cmd/compile/internal/gc/pgen.go:277 +0x39e fp=0xc00aa37708 sp=0xc00aa37690 pc=0xad711e
        /usr/local/go/src/cmd/compile/internal/gc/pgen.go:220 +0xc5 fp=0xc00aa37760 sp=0xc00aa37708 pc=0xad6c65
        /usr/local/go/src/cmd/compile/internal/gc/main.go:762 +0x3525 fp=0xc00aa37f10 sp=0xc00aa37760 pc=0xaabbe5
        /usr/local/go/src/cmd/compile/main.go:52 +0xb1 fp=0xc00aa37f88 sp=0xc00aa37f10 pc=0xbf90d1
        /usr/local/go/src/runtime/proc.go:225 +0x256 fp=0xc00aa37fe0 sp=0xc00aa37f88 pc=0x439d76
        /usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc00aa37fe8 sp=0xc00aa37fe0 pc=0x46f161
2021/03/11 10:21:46 [INFO] Cleaning up temporary folder: /tmp/buildenv_2021-03-11-1021.749880544
2021/03/11 10:21:46 [FATAL] exit status 2
francislavoie wrote this answer on 2021-03-11

How much RAM does your machine have?

ThukuWakogi wrote this answer on 2021-03-11

Its a digitalocean server.

after running free -h --si

              total        used        free      shared  buff/cache   available
Mem:           1.0G        541M        361M         14M        106M        335M
Swap:            0B          0B          0B
francislavoie wrote this answer on 2021-03-11

You'd probably be better off building on your local machine then copying the binary to your server. Golang can cross-compile by using environment variables https://caddyserver.com/docs/build#cross-platform. I don't think there's much we can do about the memory usage of the build pipeline.

francislavoie wrote this answer on 2021-03-11

FWIW, I find that guide you linked to be pretty overly complicated. My recommendation would be to instead install Caddy using our cloudsmith repo, which sets up the systemd service and other accompanying files https://caddyserver.com/docs/install#debian-ubuntu-raspbian and then follow these instructions to maintain your custom build https://github.com/caddyserver/website/pull/141/files?short_path=020f9b6#diff-020f9b6f3fa4b829965ac68e40dd3974c83d8c0e52e5ee499f3f8c690fde227d (which will be merged to our docs soon, but is just in a PR for now)

It seems like you're using a stock build of Caddy though (i.e. no plugins added to Caddy), in which case that entire guide is made redundant by just installing the apt repo we provide (you don't need to build Caddy yourself).

I wish people would just refer to our official documentation rather than use third party tutorials for this sort of thing.

ThukuWakogi wrote this answer on 2021-03-11

Installation was successful using the cloudsmith repo. I am grateful for your help.

More Details About Repo
Owner Name caddyserver
Repo Name xcaddy
Full Name caddyserver/xcaddy
Language Go
Created Date 2020-03-21
Updated Date 2022-09-22
Star Count 381
Watcher Count 14
Fork Count 72
Issue Count 3


Issue Title Created Date Comment Count Updated Date
[Help] How to use CRACO with yarnPnp or pnpm? 0 2022-08-17 2022-09-16
Deserialization Error when presented with non-standard (but still compliant) RPC responses 1 2022-07-27 2022-09-04
software reset in ems-esp32 v3.4.1b0 after fetching call with /value 6 2022-05-26 2022-08-09
Build issue on master 1 2021-03-29 2022-08-02
Dynamic series in chart 1 2021-06-25 2022-09-09
Health Bar Position 2 2022-08-01 2022-09-22
Fails to run on RX 6800 with Radeon Software 21.10.1 4 2021-10-06 2022-03-09
Xp3 Packaging error 0 2021-10-12 2022-01-16
expand faster in sympy 3 2022-02-21 2022-08-27
vite-node uses a stale update in watch mode 2 2022-07-09 2022-09-01
Error running flutter sdk-path 2 2021-05-30 2022-08-21
email through Office 365 relay 3 2017-01-26 2022-09-05
When deleting a line item, make returning to on-hand stock optional 5 2022-01-20 2022-09-23
missing permissions for ES on search head 0 2021-09-09 2022-08-15
fitz has a dependency on frontend that is not in the package 2 2022-01-15 2022-09-01
NDI installation on Mac failed 1 2021-12-28 2022-09-22
Backspace not working correctly for multi-paragraph content pasted from Google Docs 1 2021-12-02 2022-09-12
image-editor focus issue 1 2021-12-23 2022-09-12
Maximum control line size validation 1 2021-03-01 2022-09-07
Active Noise Control mission from Jay unable to find and assign mission target 1 2022-02-01 2022-09-28
Put images related to Visualisation & Data Science tab under Ecosystem Section in a separate folder. 8 2021-10-23 2022-09-12
Mesh Texturing 0 2021-08-26 2022-01-18
I am pretty sure that on 1.16 sorting chest's from expanded storage mod was working but on 1.18 it is not 1 2022-01-07 2022-09-14
TownNPCProfile system completion and extension for moddin' purposes 1 2022-04-13 2022-09-07
Authorize with Mautic is KO 0 2021-09-15 2022-09-24
Private submodules fail to update 1 2021-02-04 2022-07-28
Set Gateway API `HTTPRoute` status 0 2021-12-23 2022-09-19
columnMenu not rendering when headerCell is specified in GridColumn component 3 2021-10-28 2022-08-29
feature: Allow execute databend-query in AWS lambda 1 2022-07-21 2022-09-08
query result error in norec mode 0 2022-03-11 2022-07-10
Particle filter in mod_sst.c 0 2021-10-14 2022-09-12
Uppercase handler names (`export function GET() {...}` etc) 7 2022-07-05 2022-09-18
Update DiffEqBase library version 10 2022-07-20 2022-09-06
Account recovery request 1 2022-03-19 2022-09-19
WPF render problems on i5-11600 (Intel UHD Graphics 750) 0 2021-09-13 2022-09-28
Component `Debug` command on Windows never results in starting debug session 13 2021-09-09 2022-09-22
Exception Thrown: The _imaging extension was built for another version of Pillow or PIL 3 2022-07-15 2022-09-26
onResponse hook is not working 7 2020-11-29 2022-09-22
Workspace-level lints 0 2022-06-25 2022-08-29
Nightlight doesn't apply to all displays 2 2021-02-01 2022-09-23
[Need Help] How to submit PR for ps_accounts and ps_eventbus? 2 2021-06-30 2022-09-12
About "margin" and "num_negative_samples" hyperparames when training embedding based models 2 2019-09-16 2022-09-21
iammeter integration support for energy dashboard 7 2021-08-29 2022-09-20
[ffmpeg] build failure (custom triplets) 3 2022-09-09 2022-09-16
Add a TabGroups.move() method 0 2022-04-25 2022-09-22
- [x] - **23000_46000_** 1 2021-03-31 2021-09-09
Composer installs dev-master instead of v3.0.0 1 2020-11-05 2022-09-18
bug: Can't match both upper and lower case arguments 8 2022-03-04 2022-09-12
上次已经启动的mock组,下次启动的时候期望能自动启动mock 0 2022-03-11 2022-09-12
Google asked me to add these things into the doc's 0 2020-12-01 2022-09-15