I have a function that is 1/1000 times getting stuck somewhere and I want to figure out where it gets frozen. This unfortunately only happens in production. I want to print the stacktrace of this function by analyzing whether it has been running for 30 mins or not.
The logic I thought of is something like this:
func funcToWatch(){
go monitor()
doSomeOtherwork()
}
func monitor(){
time.Sleep(time.Minute*30)
printStackTraceOffuncToWatch()
}
I can't find out how to print the stacktrace of this function from its monitoring function inside another goroutine. Any ideas?
One thing is to print all the stacktraces of all the goroutines but there are simply too many concurrent tasks that I'll be unable to figure out which one is stuck.