packagetcpreuseimport("net""os")// reuseErrShouldRetry diagnoses whether to retry after a reuse error.// if we failed to bind, we should retry. if bind worked and this is a// real dial error (remote end didnt answer) then we should not retry.funcreuseErrShouldRetry(errerror)bool{iferr==nil{returnfalse// hey, it worked! no need to retry.}// if it's a network timeout error, it's a legitimate failure.ifnerr,ok:=err.(net.Error);ok&&nerr.Timeout(){returnfalse}e,ok:=err.(*net.OpError)if!ok{returntrue}e1,ok:=e.Err.(*os.PathError)if!ok{returntrue}switche1.Err.Error(){case"address in use":returntruecase"connection refused":returnfalsedefault:returntrue// optimistically default to retry.}}