淺析goland等待鎖問(wèn)題
問(wèn)題描述:
向后臺(tái)發(fā)送了一個(gè)URL請(qǐng)求,竟然一直卡住,沒(méi)有返回,就一直卡著
問(wèn)題分析定位:
一開(kāi)始還以為是網(wǎng)絡(luò),還是什么其它奇怪的原因,畢竟之前好好的。
這里應(yīng)該第一時(shí)間思考環(huán)境的變化,網(wǎng)絡(luò)、程序版本、還是什么地方變化了。
后來(lái)又試了好幾次,發(fā)現(xiàn)還是一樣,想到了將Pod的數(shù)目改成了2個(gè),于是估計(jì)是等待鎖或者死鎖之類的。
通過(guò)以下鏈接獲取調(diào)試信息:
curl “127.0.0.1:43411/debug/pprof/goroutine?debug=1” > 1.out
curl “127.0.0.1:43411/debug/pprof/goroutine?debug=2” > 1.log
搜索卡住的請(qǐng)求方法名,果真搜到一些,goroutine 17002 [semacquire, 5 minutes]:表示17002這個(gè)goroutine正在等待獲取鎖,等了5分鐘了。
又有一個(gè)正在運(yùn)行中的同名方法,估計(jì)是大家都在等它的鎖,看來(lái)代碼,果然有一個(gè)鎖。
但是這個(gè)goroutine調(diào)用棧最上層是SetDataNodeCarry,看到其方法內(nèi)部,發(fā)現(xiàn)其也加了一個(gè)鎖,不過(guò)其就是簡(jiǎn)單的對(duì)一個(gè)字段的變更進(jìn)行加鎖。
分析其使用的鎖相關(guān)的代碼,大家沒(méi)有重疊,每一次加鎖只不過(guò)是保證數(shù)據(jù)的原子性和一致性而已,所以不會(huì)有死鎖的問(wèn)題。
閱讀SetDataNodeCarry附近的代碼,有一個(gè)for availCarryCount < needSelectedNum {},之前沒(méi)仔細(xì)看,這里竟然可能是一個(gè)死循環(huán),分析了一下環(huán)境的變化,果然是因?yàn)榄h(huán)境不同了,導(dǎo)致這里的循環(huán)無(wú)法跳出。
總結(jié)
遇到此類問(wèn)題首先不能慌,之后不能逃避問(wèn)題。
需要將問(wèn)題盡可能地記錄,以便于還原,同時(shí)還要基于現(xiàn)在的情況進(jìn)行調(diào)試,千萬(wàn)不能想著重啟會(huì)好,不能逃避問(wèn)題。
后面解決問(wèn)題的步驟還可以,不過(guò)這個(gè)問(wèn)題本身也不是很難。
------------記錄
1 @ 0x47fc42 0x80fb0d 0x811270 0x80b86e 0x7ba758 0x7e0686 0x7f24fa 0x81d712 0x6ff9b4 0x7018b6 0x702c88 0x6fe971 0x469581 #0x47fc41 sync.(*RWMutex).Unlock+0xb1 /usr/local/go/src/sync/rwmutex.go:113 #0x80fb0c [go文件路徑]m.(*Pod).SetDataNodeCarry+0x6c /go/src/[go文件路徑]m/t.go:777 #0x81126f [go文件路徑]m.pts.ptsn+0x5f /go/src/[go文件路徑]m/t.go:1059 #0x80b86d [go文件路徑]m.(*t).ctcpd+0x83d /go/src/[go文件路徑]m/t.go:453 #0x7ba757 [go文件路徑]m.(*c).cDP+0x1e7 /go/src/[go文件路徑]m/c.go:558 #0x7e0685 [go文件路徑]m.(*m).cDP+0x375 /go/src/[go文件路徑]m/handle_admin.go:353 #0x7f24f9 [go文件路徑]m.(*m).ServeHTTP+0x1659 /go/src/[go文件路徑]m/http_server.go:188 #0x81d711 [go文件路徑]m.(*m).handlerWithInterceptor.func1+0x81 /go/src/[go文件路徑]m/http_server.go:160 #0x6ff9b3 net/http.HandlerFunc.ServeHTTP+0x43 /usr/local/go/src/net/http/server.go:1995 #0x7018b5 net/http.(*ServeMux).ServeHTTP+0x1d5 /usr/local/go/src/net/http/server.go:2375 #0x702c87 net/http.serverHandler.ServeHTTP+0xa7 /usr/local/go/src/net/http/server.go:2774 #0x6fe970 net/http.(*conn).serve+0x850 /usr/local/go/src/net/http/server.go:1878 2 @ 0x43c20f 0x44c609 0x44c5df 0x44c37d 0x47ecb9 0x7ba6ad 0x7e0686 0x7f24fa 0x81d712 0x6ff9b4 0x7018b6 0x702c88 0x6fe971 0x469581 #0x44c37c sync.runtime_SemacquireMutex+0x3c /usr/local/go/src/runtime/sema.go:71 #0x47ecb8 sync.(*Mutex).Lock+0x108 /usr/local/go/src/sync/mutex.go:134 #0x7ba6ac [go文件路徑]m.(*c).cDP+0x13c /go/src/[go文件路徑]m/c.go:554 #0x7e0685 [go文件路徑]m.(*m).cDP+0x375 /go/src/[go文件路徑]m/handle_admin.go:353 #0x7f24f9 [go文件路徑]m.(*m).ServeHTTP+0x1659 /go/src/[go文件路徑]m/http_server.go:188 #0x81d711 [go文件路徑]m.(*m).handlerWithInterceptor.func1+0x81 /go/src/[go文件路徑]m/http_server.go:160 #0x6ff9b3 net/http.HandlerFunc.ServeHTTP+0x43 /usr/local/go/src/net/http/server.go:1995 #0x7018b5 net/http.(*ServeMux).ServeHTTP+0x1d5 /usr/local/go/src/net/http/server.go:2375 #0x702c87 net/http.serverHandler.ServeHTTP+0xa7 /usr/local/go/src/net/http/server.go:2774 #0x6fe970 net/http.(*conn).serve+0x850 /usr/local/go/src/net/http/server.go:1878
goroutine 13994 [runnable]: sync.(*Mutex).Lock(0xc002300468) /usr/local/go/src/sync/mutex.go:72 +0x2c9 sync.(*RWMutex).Lock(0xc002300468) /usr/local/go/src/sync/rwmutex.go:93 +0x2d [go文件路徑]m.(*Pod).SetDataNodeCarry(0xc0023003f0, 0x4024000000000000) /go/src/[go文件路徑]m/t.go:774 +0x36 [go文件路徑]m.pts.ptsn(0xc003b17810, 0x2, 0x2, 0x0, 0x3) /go/src/[go文件路徑]m/t.go:1059 +0x60 [go文件路徑]m.(*t).ctcpd(0xc0000ef090, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x6, 0xc002275958, ...) /go/src/[go文件路徑]m/t.go:453 +0x83e [go文件路徑]m.(*c).cDP(0xc00223c000, 0xc00286e673, 0xe, 0xc00286e65f, 0x6, 0x0, 0x0, 0x0) /go/src/[go文件路徑]m/c.go:558 +0x1e8 [go文件路徑]m.(*m).cDP(0xc0009aca90, 0xabfd80, 0xc0031a1260, 0xc00296be00) /go/src/[go文件路徑]m/handle_admin.go:353 +0x376 [go文件路徑]m.(*m).ServeHTTP(0xc0009aca90, 0xabfd80, 0xc0031a1260, 0xc00296be00) /go/src/[go文件路徑]m/http_server.go:188 +0x165a [go文件路徑]m.(*m).handlerWithInterceptor.func1(0xabfd80, 0xc0031a1260, 0xc00296be00) /go/src/[go文件路徑]m/http_server.go:160 +0x82 net/http.HandlerFunc.ServeHTTP(0xc000990300, 0xabfd80, 0xc0031a1260, 0xc00296be00) /usr/local/go/src/net/http/server.go:1995 +0x44 net/http.(*ServeMux).ServeHTTP(0x10a3520, 0xabfd80, 0xc0031a1260, 0xc00296be00) /usr/local/go/src/net/http/server.go:2375 +0x1d6 net/http.serverHandler.ServeHTTP(0xc0000dad00, 0xabfd80, 0xc0031a1260, 0xc00296be00) /usr/local/go/src/net/http/server.go:2774 +0xa8 net/http.(*conn).serve(0xc003b19860, 0xac1d80, 0xc0009a9e40) /usr/local/go/src/net/http/server.go:1878 +0x851 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2884 +0x2f4 goroutine 17002 [semacquire, 5 minutes]: sync.runtime_SemacquireMutex(0xc0026fc460, 0x419400) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc0026fc45c) /usr/local/go/src/sync/mutex.go:134 +0x109 [go文件路徑]m.(*c).cDP(0xc00223c000, 0xc00002a083, 0xe, 0xc00002a06f, 0x6, 0x0, 0x0, 0x0) /go/src/[go文件路徑]m/c.go:554 +0x13d [go文件路徑]m.(*m).cDP(0xc0009aca90, 0xabfd80, 0xc0031a0620, 0xc002988900) /go/src/[go文件路徑]m/handle_admin.go:353 +0x376 [go文件路徑]m.(*m).ServeHTTP(0xc0009aca90, 0xabfd80, 0xc0031a0620, 0xc002988900) /go/src/[go文件路徑]m/http_server.go:188 +0x165a [go文件路徑]m.(*m).handlerWithInterceptor.func1(0xabfd80, 0xc0031a0620, 0xc002988900) /go/src/[go文件路徑]m/http_server.go:160 +0x82 net/http.HandlerFunc.ServeHTTP(0xc000990300, 0xabfd80, 0xc0031a0620, 0xc002988900) /usr/local/go/src/net/http/server.go:1995 +0x44 net/http.(*ServeMux).ServeHTTP(0x10a3520, 0xabfd80, 0xc0031a0620, 0xc002988900) /usr/local/go/src/net/http/server.go:2375 +0x1d6 net/http.serverHandler.ServeHTTP(0xc0000dad00, 0xabfd80, 0xc0031a0620, 0xc002988900) /usr/local/go/src/net/http/server.go:2774 +0xa8 net/http.(*conn).serve(0xc003b18640, 0xac1d80, 0xc00298e940) /usr/local/go/src/net/http/server.go:1878 +0x851 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2884 +0x2f4 goroutine 14532 [semacquire, 11 minutes]: sync.runtime_SemacquireMutex(0xc0026fc460, 0x419400) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc0026fc45c) /usr/local/go/src/sync/mutex.go:134 +0x109 [go文件路徑]m.(*c).cDP(0xc00223c000, 0xc003f74303, 0xe, 0xc003f742ef, 0x6, 0x0, 0x0, 0x0) /go/src/[go文件路徑]m/c.go:554 +0x13d [go文件路徑]m.(*m).cDP(0xc0009aca90, 0xabfd80, 0xc00454a620, 0xc004544800) /go/src/[go文件路徑]m/handle_admin.go:353 +0x376 [go文件路徑]m.(*m).ServeHTTP(0xc0009aca90, 0xabfd80, 0xc00454a620, 0xc004544800) /go/src/[go文件路徑]m/http_server.go:188 +0x165a [go文件路徑]m.(*m).handlerWithInterceptor.func1(0xabfd80, 0xc00454a620, 0xc004544800) /go/src/[go文件路徑]m/http_server.go:160 +0x82 net/http.HandlerFunc.ServeHTTP(0xc000990300, 0xabfd80, 0xc00454a620, 0xc004544800) /usr/local/go/src/net/http/server.go:1995 +0x44 net/http.(*ServeMux).ServeHTTP(0x10a3520, 0xabfd80, 0xc00454a620, 0xc004544800) /usr/local/go/src/net/http/server.go:2375 +0x1d6 net/http.serverHandler.ServeHTTP(0xc0000dad00, 0xabfd80, 0xc00454a620, 0xc004544800) /usr/local/go/src/net/http/server.go:2774 +0xa8 net/http.(*conn).serve(0xc002e17540, 0xac1d80, 0xc002a74780) /usr/local/go/src/net/http/server.go:1878 +0x851 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2884 +0x2f4
總結(jié)
到此這篇關(guān)于goland等待鎖問(wèn)題的文章就介紹到這了,更多相關(guān)goland等待鎖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
GOLANG使用Context實(shí)現(xiàn)傳值、超時(shí)和取消的方法
這篇文章主要介紹了GOLANG使用Context實(shí)現(xiàn)傳值、超時(shí)和取消的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01golang 并發(fā)編程之生產(chǎn)者消費(fèi)者詳解
這篇文章主要介紹了golang 并發(fā)編程之生產(chǎn)者消費(fèi)者詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-05-05golang搭建靜態(tài)web服務(wù)器的實(shí)現(xiàn)方法
這篇文章主要介紹了golang搭建靜態(tài)web服務(wù)器的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Go 語(yǔ)言json.Unmarshal 遇到的小問(wèn)題(推薦)
這篇文章主要介紹了 Go 語(yǔ)言json.Unmarshal 遇到的小問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07Go實(shí)現(xiàn)分布式系統(tǒng)高可用限流器實(shí)戰(zhàn)
這篇文章主要為大家介紹了Go實(shí)現(xiàn)分布式系統(tǒng)高可用限流器實(shí)戰(zhàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06Go語(yǔ)言實(shí)現(xiàn)服務(wù)端消息接收和發(fā)送
這篇文章主要為大家詳細(xì)介紹了Go語(yǔ)言實(shí)現(xiàn)服務(wù)端消息接收和發(fā)送功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07一文帶你掌握Go語(yǔ)言并發(fā)模式中的Context的上下文管理
在?Go?的日常開(kāi)發(fā)中,Context?上下文對(duì)象無(wú)處不在,無(wú)論是處理網(wǎng)絡(luò)請(qǐng)求、數(shù)據(jù)庫(kù)操作還是調(diào)用?RPC?等場(chǎng)景,那你真的熟悉它的正確用法嗎,隨著本文一探究竟吧2023-05-05淺談Go語(yǔ)言不提供隱式數(shù)字轉(zhuǎn)換的原因
本文主要介紹了淺談Go語(yǔ)言不提供隱式數(shù)字轉(zhuǎn)換的原因,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03