mirror of https://github.com/cbeuw/Cloak
Use time.AfterFunc for session inactivity timeout to reduce goroutine count
This commit is contained in:
parent
a3520c1018
commit
c0040f20c3
|
|
@ -111,7 +111,7 @@ func MakeSession(id uint32, config SessionConfig) *Session {
|
||||||
sesh.maxStreamUnitWrite = sesh.MsgOnWireSizeLimit - frameHeaderLength - sesh.Obfuscator.maxOverhead
|
sesh.maxStreamUnitWrite = sesh.MsgOnWireSizeLimit - frameHeaderLength - sesh.Obfuscator.maxOverhead
|
||||||
|
|
||||||
sesh.sb = makeSwitchboard(sesh)
|
sesh.sb = makeSwitchboard(sesh)
|
||||||
go sesh.timeoutAfter(sesh.InactivityTimeout)
|
time.AfterFunc(sesh.InactivityTimeout, sesh.checkTimeout)
|
||||||
return sesh
|
return sesh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,7 +204,7 @@ func (sesh *Session) closeStream(s *Stream, active bool) error {
|
||||||
return sesh.Close()
|
return sesh.Close()
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("session %v has no active stream left", sesh.id)
|
log.Debugf("session %v has no active stream left", sesh.id)
|
||||||
go sesh.timeoutAfter(sesh.InactivityTimeout)
|
time.AfterFunc(sesh.InactivityTimeout, sesh.checkTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -334,9 +334,7 @@ func (sesh *Session) IsClosed() bool {
|
||||||
return atomic.LoadUint32(&sesh.closed) == 1
|
return atomic.LoadUint32(&sesh.closed) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sesh *Session) timeoutAfter(to time.Duration) {
|
func (sesh *Session) checkTimeout() {
|
||||||
time.Sleep(to)
|
|
||||||
|
|
||||||
if sesh.streamCount() == 0 && !sesh.IsClosed() {
|
if sesh.streamCount() == 0 && !sesh.IsClosed() {
|
||||||
sesh.SetTerminalMsg("timeout")
|
sesh.SetTerminalMsg("timeout")
|
||||||
sesh.Close()
|
sesh.Close()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue