misc other fixes

This commit is contained in:
Arceliar
2019-09-18 18:33:51 -05:00
parent 2dc136f94a
commit 2d64a6380a
3 changed files with 11 additions and 15 deletions

View File

@@ -207,11 +207,12 @@ func (t *tcp) listener(l *TcpListener, listenaddr string) {
}
// Checks if we already are calling this address
func (t *tcp) isAlreadyCalling(saddr string) bool {
func (t *tcp) startCalling(saddr string) bool {
t.mutex.Lock()
defer t.mutex.Unlock()
_, isIn := t.calls[saddr]
return isIn
t.calls[saddr] = struct{}{}
return !isIn
}
// Checks if a connection already exists.
@@ -225,12 +226,9 @@ func (t *tcp) call(saddr string, options interface{}, sintf string) {
if sintf != "" {
callname = fmt.Sprintf("%s/%s", saddr, sintf)
}
if t.isAlreadyCalling(callname) {
if !t.startCalling(callname) {
return
}
t.mutex.Lock()
t.calls[callname] = struct{}{}
t.mutex.Unlock()
defer func() {
// Block new calls for a little while, to mitigate livelock scenarios
time.Sleep(default_timeout)