recover from a unexpected fault address

1,611 views
Skip to first unread message

Mayank Jha

unread,
Jul 1, 2019, 12:03:21 PM7/1/19
to golang-nuts
unexpected fault address 0x0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0xd9c026]

goroutine 11707890 [running]:
runtime.throw(0x13c74b7, 0x5)
/usr/local/go/src/runtime/panic.go:617 +0x72 fp=0xc0080ac5f0 sp=0xc0080ac5c0 pc=0x42f5c2
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:397 +0x401 fp=0xc0080ac620 sp=0xc0080ac5f0 pc=0x444cf1

Is there a way one can recover from such errors ? when does such error happen ? Any ideas ?

Kurtis Rader

unread,
Jul 1, 2019, 12:10:08 PM7/1/19
to Mayank Jha, golang-nuts
Your program dereferenced a NULL pointer. This is most likely to be caused by  C/C++ code you've linked with your Go code. You'll need to find out what function is at address 0xd9c026. Try doing "ulimit -c unlimited" to enable a core dump that you can then examine using a debugger like gdb.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/7959bb0d-de87-49ae-828c-d3e02e062d7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Robert Engels

unread,
Jul 1, 2019, 12:36:34 PM7/1/19
to Mayank Jha, golang-nuts

They are almost certainly caused by a 1) bug in Go, 2) improper use of CGO, 3) improper use of unsafe.

With 3 being most likely, and most likely caused by overwriting memory buffers.

You don't want to recover from these - need to fix the source of the problem. If you included more of the stack trace it might give a better idea of the cause of the problem.

Berkant Ay

unread,
Feb 13, 2023, 12:29:14 PM2/13/23
to golang-nuts
Hi everyone I also had the same problem and I am wrapping a DLL using CGO. What I found out is that when I do the operations (print-out for instance) inside the function that I wrapped there is no error. However when I pass the value inside wrapped function to my main logic it works for some amount of cycles and fails at some point. My stack trace is:

Note: my function is passed as callback to wrapped dll function.

```
| Mon Feb 13 10:31:18 +03 2023 | Consumer called.
unexpected fault address 0x3200000031
fatal error: fault
[signal 0xc0000005 code=0x0 addr=0x3200000031 pc=0x7ff6feb59783]

goroutine 17 [running, locked to thread]:
runtime.throw({0x7ff6feb94c70?, 0xc000053d48?})
        C:/Program Files/Go/src/runtime/panic.go:1047 +0x65 fp=0xc000053d10 sp=0xc000053ce0 pc=0x7ff6feaf6085
runtime.sigpanic()
        C:/Program Files/Go/src/runtime/signal_windows.go:261 +0x125 fp=0xc000053d58 sp=0xc000053d10 pc=0x7ff6feb07c45
communicationmanager/communicationmanager.goPropertyConsumerCallback(0xc0000140c0?, 0x0?, 0xc00010a070)
        C:/Users/z004djvv/Desktop/Projects/orcla-diagdata/comanager/communicationmanager/communicationmanager.go:214 +0x163 fp=0xc000053e08 sp=0xc000053d58 pc=0x7ff6feb59783
_cgoexp_acedfbcbc8a0_goPropertyConsumerCallback(0x7ff6feb9ecc0?)
        _cgo_gotypes.go:212 +0x27 fp=0xc000053e30 sp=0xc000053e08 pc=0x7ff6feb59e07
runtime.cgocallbackg1(0x7ff6feb59de0, 0xc000053fe0?, 0x0)
        C:/Program Files/Go/src/runtime/cgocall.go:316 +0x2c2 fp=0xc000053f00 sp=0xc000053e30 pc=0x7ff6feac4242
runtime.cgocallbackg(0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/cgocall.go:235 +0x105 fp=0xc000053f90 sp=0xc000053f00 pc=0x7ff6feac3e85
runtime.cgocallbackg(0x7ff6feb59de0, 0xea24bfeae0, 0x0)
        <autogenerated>:1 +0x36 fp=0xc000053fb8 sp=0xc000053f90 pc=0x7ff6feb21c16
runtime.cgocallback(0x0, 0x0, 0x0)
        C:/Program Files/Go/src/runtime/asm_amd64.s:994 +0xd7 fp=0xc000053fe0 sp=0xc000053fb8 pc=0x7ff6feb1fa37
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000053fe8 sp=0xc000053fe0 pc=0x7ff6feb1fca1

goroutine 1 [sleep]:
runtime.gopark(0x2527efe7aec58?, 0x0?, 0x0?, 0x0?, 0xc00010a000?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003ebed8 sp=0xc0003ebeb8 pc=0x7ff6feaf8b56
time.Sleep(0x3b9aca00)
        C:/Program Files/Go/src/runtime/time.go:195 +0x13c fp=0xc0003ebf18 sp=0xc0003ebed8 pc=0x7ff6feb1ca3c
main.main()
        C:/Users/z004djvv/Desktop/Projects/orcla-diagdata/cmd/main.go:24 +0xfc fp=0xc0003ebf80 sp=0xc0003ebf18 pc=0x7ff6feb5a1bc
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:250 +0x1fe fp=0xc0003ebfe0 sp=0xc0003ebf80 pc=0x7ff6feaf87be
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003ebfe8 sp=0xc0003ebfe0 pc=0x7ff6feb1fca1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00004dfb0 sp=0xc00004df90 pc=0x7ff6feaf8b56
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.forcegchelper()
        C:/Program Files/Go/src/runtime/proc.go:302 +0xb1 fp=0xc00004dfe0 sp=0xc00004dfb0 pc=0x7ff6feaf89f1
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00004dfe8 sp=0xc00004dfe0 pc=0x7ff6feb1fca1
created by runtime.init.6
        C:/Program Files/Go/src/runtime/proc.go:290 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00004ff90 sp=0xc00004ff70 pc=0x7ff6feaf8b56
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
        C:/Program Files/Go/src/runtime/mgcsweep.go:297 +0xd7 fp=0xc00004ffc8 sp=0xc00004ff90 pc=0x7ff6feae37d7
runtime.gcenable.func1()
        C:/Program Files/Go/src/runtime/mgc.go:178 +0x26 fp=0xc00004ffe0 sp=0xc00004ffc8 pc=0x7ff6fead8526
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x7ff6feb1fca1
created by runtime.gcenable
        C:/Program Files/Go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc000016070?, 0x7ff6febb9660?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00005ff70 sp=0xc00005ff50 pc=0x7ff6feaf8b56
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x7ff6fec23e60)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:389 +0x53 fp=0xc00005ffa0 sp=0xc00005ff70 pc=0x7ff6feae1813
runtime.bgscavenge(0x0?)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:622 +0x65 fp=0xc00005ffc8 sp=0xc00005ffa0 pc=0x7ff6feae1e25
runtime.gcenable.func2()
        C:/Program Files/Go/src/runtime/mgc.go:179 +0x26 fp=0xc00005ffe0 sp=0xc00005ffc8 pc=0x7ff6fead84c6
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00005ffe8 sp=0xc00005ffe0 pc=0x7ff6feb1fca1
created by runtime.gcenable
        C:/Program Files/Go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [finalizer wait]:
runtime.gopark(0x7ff6fec24260?, 0xc00004aea0?, 0x0?, 0x0?, 0xc000051f70?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000051e28 sp=0xc000051e08 pc=0x7ff6feaf8b56
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.runfinq()
        C:/Program Files/Go/src/runtime/mfinal.go:180 +0x10f fp=0xc000051fe0 sp=0xc000051e28 pc=0x7ff6fead762f
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000051fe8 sp=0xc000051fe0 pc=0x7ff6feb1fca1
created by runtime.createfing
        C:/Program Files/Go/src/runtime/mfinal.go:157 +0x45

goroutine 6 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000061f50 sp=0xc000061f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000061fe0 sp=0xc000061f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000061fe8 sp=0xc000061fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 19 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000429f50 sp=0xc000429f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000429fe0 sp=0xc000429f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000429fe8 sp=0xc000429fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 7 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000425f50 sp=0xc000425f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000425fe0 sp=0xc000425f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000425fe8 sp=0xc000425fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 8 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc000427f50 sp=0xc000427f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000427fe0 sp=0xc000427f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000427fe8 sp=0xc000427fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 35 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00005df50 sp=0xc00005df30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc00005dfe0 sp=0xc00005df50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00005dfe8 sp=0xc00005dfe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 9 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003cff50 sp=0xc0003cff30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0003cffe0 sp=0xc0003cff50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003cffe8 sp=0xc0003cffe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 20 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc00042bf50 sp=0xc00042bf30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc00042bfe0 sp=0xc00042bf50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00042bfe8 sp=0xc00042bfe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 10 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003d1f50 sp=0xc0003d1f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0003d1fe0 sp=0xc0003d1f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003d1fe8 sp=0xc0003d1fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 21 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003cbf50 sp=0xc0003cbf30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0003cbfe0 sp=0xc0003cbf50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003cbfe8 sp=0xc0003cbfe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 11 [GC worker (idle)]:
runtime.gopark(0x2527e3e93f600?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003d7f50 sp=0xc0003d7f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0003d7fe0 sp=0xc0003d7f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003d7fe8 sp=0xc0003d7fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 22 [GC worker (idle)]:
runtime.gopark(0x2527e3e93f600?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003cdf50 sp=0xc0003cdf30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0003cdfe0 sp=0xc0003cdf50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003cdfe8 sp=0xc0003cdfe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25

goroutine 12 [GC worker (idle)]:
runtime.gopark(0x2527e3eec9774?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0xc0003d9f50 sp=0xc0003d9f30 pc=0x7ff6feaf8b56
runtime.gcBgMarkWorker()
        C:/Program Files/Go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0003d9fe0 sp=0xc0003d9f50 pc=0x7ff6feada531
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0003d9fe8 sp=0xc0003d9fe0 pc=0x7ff6feb1fca1
created by runtime.gcBgMarkStartWorkers
        C:/Program Files/Go/src/runtime/mgc.go:1159 +0x25
```


1 Temmuz 2019 Pazartesi tarihinde saat 19:36:34 UTC+3 itibarıyla Robert Engels şunları yazdı:

XL T

unread,
Jul 14, 2023, 9:23:38 AM7/14/23
to golang-nuts
my case is what Robert said.

code below could cause this err, and not recover by go:
---------------------------------------------------------------------------
 s := "123"
 sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))

 b := []byte{}
 bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
 bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
 defer func(){
        e := recover()
        fmt.Println(e)
 }()
 b[0] = '4' // this line is the reason, because i modified the s variable.
----------------------------------------------------------------------

String is not mutable, and what you do is to change this, and so err-ed,  this kind of err can not be captured by recover.
you should avoid this behavior, follow the rule of String type.
Reply all
Reply to author
Forward
0 new messages