Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault from release binary #675

Closed
joatca opened this issue Apr 23, 2023 · 14 comments · Fixed by #691
Closed

Segmentation fault from release binary #675

joatca opened this issue Apr 23, 2023 · 14 comments · Fixed by #691
Labels
Milestone

Comments

@joatca
Copy link

joatca commented Apr 23, 2023

Describe the bug

Segfault after setup with the current release binary running in a 1G VPS.

Steps to reproduce (if necessary)

Steps to reproduce the behavior:

  1. Following the Getting Started guide, ./writefreely config start and ./writefreely keys generate work as expected
  2. Running writefreely segfaults:
[blog@hilly writefreely]$ ./writefreely
2023/04/23 13:26:21 Starting WriteFreely 0.13.2...
2023/04/23 13:26:21 Loading config.ini configuration...
2023/04/23 13:26:21 Loading templates...
2023/04/23 13:26:21 Loading pages...
2023/04/23 13:26:21 Loading user pages...
2023/04/23 13:26:21 Loading encryption keys...
2023/04/23 13:26:21 Connecting to sqlite3 database...
2023/04/23 13:26:21 Adding {domain} routes (single user)...
2023/04/23 13:26:21 Going to serve...
2023/04/23 13:26:21 Serving on http://localhost:8080
2023/04/23 13:26:21 ---
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x1d93a0 pc=0x7f62900a6f16]

runtime stack:
runtime.throw({0x164cafe?, 0x352?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7f6290d02fc8 sp=0x7f6290d02f98 pc=0x43859d
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:819 +0x369 fp=0x7f6290d03018 sp=0x7f6290d02fc8 pc=0x44e249

goroutine 238 [syscall]:
runtime.cgocall(0x1334f30, 0xc0006fd598)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc0006fd570 sp=0xc0006fd538 pc=0x405bfc
net._C2func_getaddrinfo(0xc0008e11c0, 0x0, 0xc0008ec660, 0xc00082cec0)
        _cgo_gotypes.go:94 +0x56 fp=0xc0006fd598 sp=0xc0006fd570 pc=0x679e96
net.cgoLookupIPCNAME.func1({0xc0008e11c0, 0x4?, 0xc0006fd630?}, 0xc0008e1020?, 0x2198d40?)
        /usr/local/go/src/net/cgo_unix.go:160 +0x9f fp=0xc0006fd5f0 sp=0xc0006fd598 pc=0x67b73f
net.cgoLookupIPCNAME({0x1620523, 0x3}, {0xc0008e1020, 0x9})
        /usr/local/go/src/net/cgo_unix.go:160 +0x173 fp=0xc0006fd738 sp=0xc0006fd5f0 pc=0x67af93
net.cgoIPLookup(0x503f65?, {0x1620523?, 0xc0006fd7d0?}, {0xc0008e1020?, 0xc000380cf0?})
        /usr/local/go/src/net/cgo_unix.go:217 +0x3b fp=0xc0006fd7a8 sp=0xc0006fd738 pc=0x67b7fb
net.cgoLookupIP.func1()
        /usr/local/go/src/net/cgo_unix.go:227 +0x36 fp=0xc0006fd7e0 sp=0xc0006fd7a8 pc=0x67bc36
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0006fd7e8 sp=0xc0006fd7e0 pc=0x4691a1
created by net.cgoLookupIP
        /usr/local/go/src/net/cgo_unix.go:227 +0x12a

goroutine 1 [select]:
runtime.gopark(0xc0004d1688?, 0x2?, 0xdf?, 0xf4?, 0xc0004d15cc?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc0004d1408 sp=0xc0004d13e8 pc=0x43b1b6
runtime.selectgo(0xc0004d1688, 0xc0004d15c8, 0xd?, 0x0, 0x10842108421084?, 0x1)
        /usr/local/go/src/runtime/select.go:328 +0x7bc fp=0xc0004d1548 sp=0xc0004d1408 pc=0x44a61c
net.(*Resolver).lookupIPAddr(0x2197460, {0x17a41f0?, 0xc000028070}, {0x1620523, 0x3}, {0xc0008e1020, 0x9})
        /usr/local/go/src/net/lookup.go:327 +0x51b fp=0xc0004d1758 sp=0xc0004d1548 pc=0x6691db
net.(*Resolver).internetAddrList(0x17a41f0?, {0x17a41f0?, 0xc000028070?}, {0x1620523, 0x3}, {0xc0008e1020?, 0xe?})
        /usr/local/go/src/net/ipsock.go:288 +0x67a fp=0xc0004d1878 sp=0xc0004d1758 pc=0x666fda
net.(*Resolver).resolveAddrList(0x18?, {0x17a41f0, 0xc000028070}, {0x16241e7, 0x6}, {0x1620523?, 0x0?}, {0xc0008e1020, 0xe}, {0x0, ...})
        /usr/local/go/src/net/dial.go:222 +0x41b fp=0xc0004d1980 sp=0xc0004d1878 pc=0x65195b
net.(*ListenConfig).Listen(0xc0004d1aa8, {0x17a41f0, 0xc000028070}, {0x1620523, 0x3}, {0xc0008e1020, 0xe})
        /usr/local/go/src/net/dial.go:625 +0x8a fp=0xc0004d1a70 sp=0xc0004d1980 pc=0x65496a
net.Listen({0x1620523?, 0xe8?}, {0xc0008e1020?, 0xc00007e301?})
        /usr/local/go/src/net/dial.go:711 +0x4b fp=0xc0004d1ac8 sp=0xc0004d1a70 pc=0x65550b
net/http.(*Server).ListenAndServe(0xc000868690)
        /usr/local/go/src/net/http/server.go:2995 +0x58 fp=0xc0004d1af8 sp=0xc0004d1ac8 pc=0x7660f8
net/http.ListenAndServe(...)
        /usr/local/go/src/net/http/server.go:3255
github.com/writefreely/writefreely.Serve(0xc000066480, 0xc000026180)
        /home/matt/projects/go/src/github.com/writefreely/writefreely/app.go:508 +0xb12 fp=0xc0004d1c78 sp=0xc0004d1af8 pc=0x11eeef2
main.legacyActions(0xc000307cc0?)
        /home/matt/projects/go/src/github.com/writefreely/writefreely/cmd/writefreely/main.go:172 +0x385 fp=0xc0004d1d08 sp=0xc0004d1c78 pc=0x126c0e5
github.com/urfave/cli/v2.(*App).RunContext(0xc0000b5520, {0x17a41f0?, 0xc000028070}, {0xc000024230, 0x1, 0x1})
        /home/matt/projects/go/pkg/mod/github.com/urfave/cli/v2@v2.5.1/app.go:322 +0x97c fp=0xc0004d1e98 sp=0xc0004d1d08 pc=0x57ec3c
github.com/urfave/cli/v2.(*App).Run(...)
        /home/matt/projects/go/pkg/mod/github.com/urfave/cli/v2@v2.5.1/app.go:224
main.main()
        /home/matt/projects/go/src/github.com/writefreely/writefreely/cmd/writefreely/main.go:118 +0x7dc fp=0xc0004d1f80 sp=0xc0004d1e98 pc=0x126bcfc
runtime.main()
        /usr/local/go/src/runtime/proc.go:250 +0x212 fp=0xc0004d1fe0 sp=0xc0004d1f80 pc=0x43adf2
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0004d1fe8 sp=0xc0004d1fe0 pc=0x4691a1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000044fb0 sp=0xc000044f90 pc=0x43b1b6
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:369
runtime.forcegchelper()
        /usr/local/go/src/runtime/proc.go:302 +0xad fp=0xc000044fe0 sp=0xc000044fb0 pc=0x43b04d
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000044fe8 sp=0xc000044fe0 pc=0x4691a1
created by runtime.init.6
        /usr/local/go/src/runtime/proc.go:290 +0x25

goroutine 3 [runnable]:
runtime.Gosched(...)
        /usr/local/go/src/runtime/proc.go:318
runtime.bgsweep(0x0?)
        /usr/local/go/src/runtime/mgcsweep.go:283 +0xfc fp=0xc0000457c8 sp=0xc000045790 pc=0x426d5c
runtime.gcenable.func1()
        /usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc0000457e0 sp=0xc0000457c8 pc=0x41b9a6
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000457e8 sp=0xc0000457e0 pc=0x4691a1
created by runtime.gcenable
        /usr/local/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc000030070?, 0x179d6b0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000045f70 sp=0xc000045f50 pc=0x43b1b6
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x2198260)
        /usr/local/go/src/runtime/mgcscavenge.go:389 +0x53 fp=0xc000045fa0 sp=0xc000045f70 pc=0x424d93
runtime.bgscavenge(0x0?)
        /usr/local/go/src/runtime/mgcscavenge.go:622 +0x65 fp=0xc000045fc8 sp=0xc000045fa0 pc=0x425385
runtime.gcenable.func2()
        /usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc000045fe0 sp=0xc000045fc8 pc=0x41b946
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000045fe8 sp=0xc000045fe0 pc=0x4691a1
created by runtime.gcenable
        /usr/local/go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [finalizer wait]:
runtime.gopark(0x2198d40?, 0xc000007860?, 0x0?, 0x0?, 0xc000044770?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000044628 sp=0xc000044608 pc=0x43b1b6
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:369
runtime.runfinq()
        /usr/local/go/src/runtime/mfinal.go:180 +0x10f fp=0xc0000447e0 sp=0xc000044628 pc=0x41aaaf
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000447e8 sp=0xc0000447e0 pc=0x4691a1
created by runtime.createfing
        /usr/local/go/src/runtime/mfinal.go:157 +0x45

goroutine 6 [GC worker (idle)]:
runtime.gopark(0x27372bfa4e1e6?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000046750 sp=0xc000046730 pc=0x43b1b6
runtime.gcBgMarkWorker()
        /usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0000467e0 sp=0xc000046750 pc=0x41daf1
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000467e8 sp=0xc0000467e0 pc=0x4691a1
created by runtime.gcBgMarkStartWorkers
        /usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 234 [runnable, locked to thread]:
runtime.gopark(0x1?, 0x2?, 0x3?, 0x0?, 0xc000047ee8?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000047ea0 sp=0xc000047e80 pc=0x43b1b6
runtime.chansend(0xc0003e1500, 0xc000047f8f, 0x1, 0x2?)
        /usr/local/go/src/runtime/chan.go:259 +0x42c fp=0xc000047f28 sp=0xc000047ea0 pc=0x407dec
runtime.chansend1(0xc000000002?, 0xc000047f98?)
        /usr/local/go/src/runtime/chan.go:145 +0x1d fp=0xc000047f58 sp=0xc000047f28 pc=0x40799d
runtime.ensureSigM.func1()
        /usr/local/go/src/runtime/signal_unix.go:1002 +0x15a fp=0xc000047fe0 sp=0xc000047f58 pc=0x44e69a
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000047fe8 sp=0xc000047fe0 pc=0x4691a1
created by runtime.ensureSigM
        /usr/local/go/src/runtime/signal_unix.go:974 +0xbd

goroutine 235 [syscall]:
runtime.notetsleepg(0x4421a5?, 0x503f65?)
        /usr/local/go/src/runtime/lock_futex.go:236 +0x34 fp=0xc0006fb7a0 sp=0xc0006fb768 pc=0x40dff4
os/signal.signal_recv()
        /usr/local/go/src/runtime/sigqueue.go:152 +0x2f fp=0xc0006fb7c0 sp=0xc0006fb7a0 pc=0x465b8f
os/signal.loop()
        /usr/local/go/src/os/signal/signal_unix.go:23 +0x19 fp=0xc0006fb7e0 sp=0xc0006fb7c0 pc=0x7fa759
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0006fb7e8 sp=0xc0006fb7e0 pc=0x4691a1
created by os/signal.Notify.func1.1
        /usr/local/go/src/os/signal/signal.go:151 +0x2a

goroutine 236 [runnable]:
github.com/writefreely/writefreely.Serve.func1()
        /home/matt/projects/go/src/github.com/writefreely/writefreely/app.go:436 fp=0xc0006fbfe0 sp=0xc0006fbfd8 pc=0x11ef420
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0006fbfe8 sp=0xc0006fbfe0 pc=0x4691a1
created by github.com/writefreely/writefreely.Serve
        /home/matt/projects/go/src/github.com/writefreely/writefreely/app.go:436 +0x16a

goroutine 237 [select]:
runtime.gopark(0xc000055c28?, 0x2?, 0x0?, 0x30?, 0xc000055c0c?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000055a98 sp=0xc000055a78 pc=0x43b1b6
runtime.selectgo(0xc000055c28, 0xc000055c08, 0x0?, 0x0, 0xc0008e8640?, 0x1)
        /usr/local/go/src/runtime/select.go:328 +0x7bc fp=0xc000055bd8 sp=0xc000055a98 pc=0x44a61c
net.cgoLookupIP({0x17a41b8, 0xc000885d80}, {0x1620523, 0x3}, {0xc0008e1020, 0x9})
        /usr/local/go/src/net/cgo_unix.go:228 +0x1aa fp=0xc000055cc8 sp=0xc000055bd8 pc=0x67ba4a
net.(*Resolver).lookupIP(0x2197460, {0x17a41b8, 0xc000885d80}, {0x1620523, 0x3}, {0xc0008e1020, 0x9})
        /usr/local/go/src/net/lookup_unix.go:74 +0x128 fp=0xc000055e18 sp=0xc000055cc8 pc=0x66a608
net.(*Resolver).lookupIP-fm({0x17a41b8?, 0xc000885d80?}, {0x1620523?, 0xc0006fea20?}, {0xc0008e1020?, 0xc000681380?})
        <autogenerated>:1 +0x5b fp=0xc000055e60 sp=0xc000055e18 pc=0x67ec7b
net.glob..func1({0x17a41b8?, 0xc000885d80?}, 0x3?, {0x1620523?, 0x40799d?}, {0xc0008e1020?, 0xc0006fc778?})
        /usr/local/go/src/net/hook.go:23 +0x3d fp=0xc000055ea0 sp=0xc000055e60 pc=0x65ebdd
net.(*Resolver).lookupIPAddr.func1()
        /usr/local/go/src/net/lookup.go:321 +0x9f fp=0xc000055f38 sp=0xc000055ea0 pc=0x669a7f
internal/singleflight.(*Group).doCall(0x2197470, 0xc0008d2c80, {0xc0008e1030, 0xd}, 0xc000380f30?)
        /usr/local/go/src/internal/singleflight/singleflight.go:95 +0x3b fp=0xc000055fa8 sp=0xc000055f38 pc=0x64dbfb
internal/singleflight.(*Group).DoChan.func1()
        /usr/local/go/src/internal/singleflight/singleflight.go:88 +0x36 fp=0xc000055fe0 sp=0xc000055fa8 pc=0x64db96
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000055fe8 sp=0xc000055fe0 pc=0x4691a1
created by internal/singleflight.(*Group).DoChan
        /usr/local/go/src/internal/singleflight/singleflight.go:88 +0x315

goroutine 228 [select]:
runtime.gopark(0xc0006fcf88?, 0x2?, 0x78?, 0xcf?, 0xc0006fcf84?)
        /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc0006fce10 sp=0xc0006fcdf0 pc=0x43b1b6
runtime.selectgo(0xc0006fcf88, 0xc0006fcf80, 0xc0006fcfa0?, 0x0, 0x10?, 0x1)
        /usr/local/go/src/runtime/select.go:328 +0x7bc fp=0xc0006fcf50 sp=0xc0006fce10 pc=0x44a61c
database/sql.(*DB).connectionOpener(0xc000377040, {0x17a41b8, 0xc000854d00})
        /usr/local/go/src/database/sql/sql.go:1224 +0x8d fp=0xc0006fcfb8 sp=0xc0006fcf50 pc=0x7c7e6d
database/sql.OpenDB.func1()
        /usr/local/go/src/database/sql/sql.go:792 +0x2e fp=0xc0006fcfe0 sp=0xc0006fcfb8 pc=0x7c624e
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0006fcfe8 sp=0xc0006fcfe0 pc=0x4691a1
created by database/sql.OpenDB
        /usr/local/go/src/database/sql/sql.go:792 +0x18d

Expected behavior

No segfault :-)

Application configuration

  • Single mode
  • Database? mysql/sqlite
  • Open registration? [no]
  • Federation enabled? [yes/no]

Version or last commit:
0.13.2

VPS details

  • 1G RAM
  • CPU:
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         40 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  1
  On-line CPU(s) list:   0
Vendor ID:               GenuineIntel
  Model name:            Intel Xeon Processor (Skylake, IBRS)
    CPU family:          6
    Model:               85
    Thread(s) per core:  1
    Core(s) per socket:  1
    Socket(s):           1
    Stepping:            4
    BogoMIPS:            4201.99
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx f
                         xsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpu
                         id tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe po
                         pcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetc
                         h cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ep
                         t vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm avx512f av
                         x512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xge
                         tbv1 xsaves arat umip pku ospke md_clear arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):     
  L1d:                   32 KiB (1 instance)
  L1i:                   32 KiB (1 instance)
  L2:                    4 MiB (1 instance)
  L3:                    16 MiB (1 instance)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0
Vulnerabilities:         
  Itlb multihit:         Not affected
  L1tf:                  Mitigation; PTE Inversion; VMX flush not necessary, SMT disabled
  Mds:                   Mitigation; Clear CPU buffers; SMT Host state unknown
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
  Retbleed:              Mitigation; IBRS
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; IBRS, IBPB conditional, STIBP disabled, RSB filling, PBRSB-eIBRS Not affe
                         cted
  Srbds:                 Not affected
  Tsx async abort:       Mitigation; Clear CPU buffers; SMT Host state unknown
@joatca
Copy link
Author

joatca commented Apr 23, 2023

Update: I failed to note which database it's using. It's SQLite.

@thebaer
Copy link
Member

thebaer commented Apr 25, 2023

Really not sure what could be causing this, but seems like something in the underlying dependencies on the machine. Here's a comment that might be helpful -- is your VPS using a glibc substitute? Or what version of glibc is it using?

@joatca
Copy link
Author

joatca commented Apr 26, 2023

Really not sure what could be causing this, but seems like something in the underlying dependencies on the machine. Here's a comment that might be helpful -- is your VPS using a glibc substitute? Or what version of glibc is it using?

Nope, it's a fairly standard Arch install, with glibc 2.37-2. I don't think that comment is the same issue; in my case the segfault isn't intermittent, it happens immediately every single time I use writefreely serve but config start and keys generate work fine. Also, it happens on two different VPS providers, in both cases the VPSes had 1G of RAM.

My desktop is also running Arch with glibc 2.37-2 and everything works fine there; no problems with serve and everything seems to work as expected.

@thebaer
Copy link
Member

thebaer commented Apr 26, 2023

It should be fine with that much RAM. This looks like the salient part to me:

goroutine 238 [syscall]:
runtime.cgocall(0x1334f30, 0xc0006fd598)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc0006fd570 sp=0xc0006fd538 pc=0x405bfc
net._C2func_getaddrinfo(0xc0008e11c0, 0x0, 0xc0008ec660, 0xc00082cec0)
        _cgo_gotypes.go:94 +0x56 fp=0xc0006fd598 sp=0xc0006fd570 pc=0x679e96
net.cgoLookupIPCNAME.func1({0xc0008e11c0, 0x4?, 0xc0006fd630?}, 0xc0008e1020?, 0x2198d40?)
        /usr/local/go/src/net/cgo_unix.go:160 +0x9f fp=0xc0006fd5f0 sp=0xc0006fd598 pc=0x67b73f
net.cgoLookupIPCNAME({0x1620523, 0x3}, {0xc0008e1020, 0x9})
        /usr/local/go/src/net/cgo_unix.go:160 +0x173 fp=0xc0006fd738 sp=0xc0006fd5f0 pc=0x67af93
net.cgoIPLookup(0x503f65?, {0x1620523?, 0xc0006fd7d0?}, {0xc0008e1020?, 0xc000380cf0?})
        /usr/local/go/src/net/cgo_unix.go:217 +0x3b fp=0xc0006fd7a8 sp=0xc0006fd738 pc=0x67b7fb
net.cgoLookupIP.func1()
        /usr/local/go/src/net/cgo_unix.go:227 +0x36 fp=0xc0006fd7e0 sp=0xc0006fd7a8 pc=0x67bc36
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0006fd7e8 sp=0xc0006fd7e0 pc=0x4691a1
created by net.cgoLookupIP
        /usr/local/go/src/net/cgo_unix.go:227 +0x12a

Could you try running writefreely with this environment variable set: GODEBUG=netdns=go, as mentioned in this comment?

@joatca
Copy link
Author

joatca commented Apr 26, 2023

Ah, that did it. Doing that gives this:

ERROR: 2023/04/26 23:36:37 app.go:511: Unable to start: listen tcp: lookup localhost on 1.1.1.1:53: no such host

That led me to find that /etc/hosts was empty. Adding the same lines as my desktop:

127.0.0.1       localhost.localdomain   localhost

...allows writefreely to start with GODEBUG=netdns=go but it still segfaults without it. I replaced all instances of localhost in config.ini with 127.0.0.1 and it now starts cleanly.

@xxxserxxx
Copy link

I don't want to start a "me too" precedent, but... me too. Exact same issue, same solution. To help any decisions about long-term resolution, I'll add:

  • running behind a reverse proxy, so I ran through the config with the external hostname as the "public" URL, but in reverse-proxy mode
  • in my case, this was on a VPS (running Arch); I don't know what my provider is running these VMs as, but I believe -- from experience -- they're VMs and not containers. Networking and disk look entirely as if it's running on metal, as opposed to the oddities you sometimes see in containers.
  • nothing on these machines are more than a few days behind the rolling updates of Arch
  • the binary was from the 0.13.2 CI release asset
  • The config generator writes "localhost," which the binary is then unable to resolve. Changing to 127.0.0.1 in the config lets it work (as does changing the DNS resolver).

@thebaer thebaer added the bug label Apr 27, 2023
@thebaer thebaer added this to the 0.14 milestone Apr 27, 2023
@thebaer
Copy link
Member

thebaer commented Apr 27, 2023

Thanks for confirming @joatca and @xxxserxxx. To solve this particular error, we can release future binaries that use Go DNS resolution instead of libc, so admins get these useful error messages (following gitea's lead here). Just need to update the Makefile for that. Otherwise agreed we might want to change the default bind address in the config generator.

If either of you want to submit a PR for those, please feel free! Otherwise will get to it when I can.

@joatca
Copy link
Author

joatca commented Apr 28, 2023

A note that replacing localhost with 127.0.0.1 isn't sufficient. It allows WF to start cleanly but attempting to follow the blog from Mastodon causes it to lookup URLs and it segfaults again. I needed Environment="GODEBUG=netdns=go" in my systemd unit.

@xxxserxxx
Copy link

@joatca while I ended up binding to a different interface (VPN), the lookups are/were only causing segfaults looking up localhost with the built-in DNS. Did you change the app.host setting?

@joatca
Copy link
Author

joatca commented Apr 28, 2023

@joatca while I ended up binding to a different interface (VPN), the lookups are/were only causing segfaults looking up localhost with the built-in DNS. Did you change the app.host setting?

Yes, I changed it to the public URL, as served by my reverse proxy. The docs say Full hostname (including scheme) users will see - is that the correct thing to do?

@xxxserxxx
Copy link

Caveat: I'm not one of the devs, so all I can say is how mine is set up.

In my config, server.bind and database.host are both set to my VPN IP. The database.host is irrelevant, because I'm using sqlite. My app.site_name is the external FQDN resolving to the reverse proxy. my app.host is the URI of the blog; basically, https://FQDN. This configuration works for me without the Go netdns setting.

thebaer added a commit that referenced this issue Apr 28, 2023
This builds with the `netgo` tag, ensuring WF binaries use Go DNS
resolution instead of libc, preventing unhelpful errors when the
application can't resolve addresses.

Closes #675
@RapidRotator
Copy link

RapidRotator commented May 26, 2023

Not sure if this is related, but I get a different segfault:

2023/05/26 06:34:09 Loading templates...
2023/05/26 06:34:09 Loading pages...
2023/05/26 06:34:09 Loading user pages...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x1253bde]

goroutine 1 [running]:
github.com/writefreely/writefreely.InitTemplates.func2({0xc0001a0de0, 0x13}, {0x0, 0x0}, {0x14?, 0x3?})
        /src/writefreely/src/writefreely-0.13.2/templates.go:150 +0x3e
path/filepath.Walk({0xc0001a0de0, 0x13}, 0xc000595b70)
        /usr/lib/go/src/path/filepath/path.go:569 +0x50
github.com/writefreely/writefreely.InitTemplates(0xc000351200)
        /src/writefreely/src/writefreely-0.13.2/templates.go:149 +0x314
github.com/writefreely/writefreely.Initialize({0x16c1580, 0xc00002e180}, 0x5?)
        /src/writefreely/src/writefreely-0.13.2/app.go:394 +0x4b
main.legacyActions(0xc0003bdb80?)
        /src/writefreely/src/writefreely-0.13.2/cmd/writefreely/main.go:161 +0x2fc
github.com/urfave/cli/v2.(*App).RunContext(0xc00008bd40, {0x16c0a28?, 0xc00011a000}, {0xc000112210, 0x1, 0x1})
        /home/builduser/go/pkg/mod/github.com/urfave/cli/v2@v2.5.1/app.go:322 +0x97c
github.com/urfave/cli/v2.(*App).Run(...)
        /home/builduser/go/pkg/mod/github.com/urfave/cli/v2@v2.5.1/app.go:224
main.main()
        /src/writefreely/src/writefreely-0.13.2/cmd/writefreely/main.go:118 +0x7d6

This is a new installation in a docker container where I successfully completed the other steps for configuration and key generation. The suggested debug statement above did not reveal anything, but it seems to complain about templates. Is there a default of example template available that I can use?

@thebaer
Copy link
Member

thebaer commented May 26, 2023

@RapidRotator That seems to be a different issue, caused by an uncaught error at templates.go:149. Could you open a separate issue for that?

@RapidRotator
Copy link

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants