I'm sorry I can not explain the question well. So, I try to use code to explain.
My problem is: I'm trying to implement a async protocol, one goroutine for Read, one goroutine for Write.
When client try to Write()/Read() but fail, I'll return back to the main goroutine.
If I don't know the status of Connection maybe one of the goroutine may hang forever.
for example, sendCmdsToSrv call Write() and failed, it quit. But recvCmdsFromSrv() may still waiting response. So the WaitGroup still waiting.
func srvService(srvAddr string) chan<- Command {
c := make(chan Command, *maxCommands)
go func(c chan Command) {
for srvConnSeq := uint32(0); ; srvConnSeq++ {
err := dialServer(srvConnSeq, &srvConn, srvAddr)
if err != nil {
break
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
sendCmdsToSrv(srvConn, srvConnSeq, c)
wg.Done()
}()
go func() {
recvCmdsFromSrv(srvConn, srvConnSeq, c)
wg.Done()
}()
wg.Wait()
}
}(c)
return c
}