Browse Source

chanDebug

Wade Simmons 1 year ago
parent
commit
f2251645bb
4 changed files with 20 additions and 0 deletions
  1. 1 0
      Makefile
  2. 3 0
      lighthouse.go
  3. 13 0
      mutex_debug.go
  4. 3 0
      mutex_nodebug.go

+ 1 - 0
Makefile

@@ -206,6 +206,7 @@ ifeq ($(words $(MAKECMDGOALS)),1)
 	@$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
 endif
 
+bin-docker: BUILD_ARGS = -tags=mutex_debug
 bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
 
 smoke-docker: bin-docker

+ 3 - 0
lighthouse.go

@@ -468,6 +468,7 @@ func (lh *LightHouse) QueryServer(ip iputil.VpnIp) {
 		return
 	}
 
+	chanDebugSend("lighthouse-query-chan")
 	lh.queryChan <- ip
 }
 
@@ -750,6 +751,8 @@ func (lh *LightHouse) startQueryWorker() {
 		nb := make([]byte, 12, 12)
 		out := make([]byte, mtu)
 
+		chanDebugRecv("lighthouse-query-chan")
+
 		for {
 			select {
 			case <-lh.ctx.Done():

+ 13 - 0
mutex_debug.go

@@ -135,6 +135,19 @@ func checkMutex(state map[mutexKey]mutexValue, add mutexKey) {
 	}
 }
 
+func chanDebugRecv(key mutexKey) {
+	m := threadLocal.Get().(map[mutexKey]mutexValue)
+	checkMutex(m, key)
+	v := mutexValue{}
+	_, v.file, v.line, _ = runtime.Caller(1)
+	m[key] = v
+}
+
+func chanDebugSend(key mutexKey) {
+	m := threadLocal.Get().(map[mutexKey]mutexValue)
+	checkMutex(m, key)
+}
+
 func (s *syncRWMutex) Lock() {
 	m := threadLocal.Get().(map[mutexKey]mutexValue)
 	checkMutex(m, s.mutexKey)

+ 3 - 0
mutex_nodebug.go

@@ -18,3 +18,6 @@ func newSyncRWMutex(mutexKey) syncRWMutex {
 func newSyncMutex(mutexKey) syncMutex {
 	return sync.Mutex{}
 }
+
+func chanDebugRecv(key mutexKey) {}
+func chanDebugSend(key mutexKey) {}