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.

On Tuesday, July 2, 2019 at 12:36:34 AM UTC+8 Robert Engels wrote:

>
> 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.
>
>
>
> -----Original Message----- 
> From: Mayank Jha 
> Sent: Jul 1, 2019 11:03 AM 
> To: golang-nuts 
> Subject: [go-nuts] recover from a unexpected fault address 
>
> 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 ?
>
> -- 
> 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
>  
> <https://groups.google.com/d/msgid/golang-nuts/7959bb0d-de87-49ae-828c-d3e02e062d7d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20d1d185-a894-4088-9889-169c301b3921n%40googlegroups.com.

Reply via email to