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

RWMutex panic stack is confuse #35614

Closed
Petelin opened this issue Nov 15, 2019 · 1 comment

Comments

@Petelin
Copy link

@Petelin Petelin commented Nov 15, 2019

this problem not happen in go1.10, but happen on go1.12,1.13

package main

import (
	"sync"
)

type client struct {
	sync.Mutex
	sync.RWMutex
}

func (c *client) do() {
	c.RWMutex.RLock()
	defer c.RWMutex.Unlock()
}

func (c *client) do2() {
	c.Mutex.Lock()
	c.Mutex.Unlock()
}

func main() {
	var c *client
	c.do()
	// c.do2()
}

what i expected is do and do2 should have almost same panic stack.

but the RLock panic print is not say c.RWMutext is nil point but RLock function have problem.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x104f17c]

goroutine 1 [running]:
sync.(*RWMutex).RLock(...)
        /usr/local/Cellar/go/1.12.5/libexec/src/sync/rwmutex.go:48
main.(*client).do(0x0)
        /Users/xiaolin.zhang/Project/gogo/test_main.go:13 +0x2c
main.main()
        /Users/xiaolin.zhang/Project/gogo/test_main.go:24 +0x2a
@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Nov 15, 2019

This looks like it is already fixed at tip.
Up to go1.13 it looks like the nil check in do is dropped because there is an unconditional load in the inlined body of RLock that does the nil check for us. But that gives an extra stack frame that doesn't really make sense.
At tip we no longer do that. I'm not sure what CL fixed this, maybe CL 200197?

@randall77 randall77 closed this Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.