Commit 848c9843 authored by alexstocks's avatar alexstocks

add logs

parent 5702c16e
...@@ -175,6 +175,7 @@ func (this *Session) IsClosed() bool { ...@@ -175,6 +175,7 @@ func (this *Session) IsClosed() bool {
select { select {
case <-this.done: case <-this.done:
return true return true
default: default:
return false return false
} }
...@@ -210,6 +211,7 @@ func (this *Session) SetRQLen(readQLen int) { ...@@ -210,6 +211,7 @@ func (this *Session) SetRQLen(readQLen int) {
this.lock.Lock() this.lock.Lock()
this.rQ = make(chan interface{}, readQLen) this.rQ = make(chan interface{}, readQLen)
log.Info("%s, [session.SetRQLen] rQ{len:%d, cap:%d}", this.Stat(), len(this.rQ), cap(this.rQ))
this.lock.Unlock() this.lock.Unlock()
} }
...@@ -221,6 +223,7 @@ func (this *Session) SetWQLen(writeQLen int) { ...@@ -221,6 +223,7 @@ func (this *Session) SetWQLen(writeQLen int) {
this.lock.Lock() this.lock.Lock()
this.wQ = make(chan interface{}, writeQLen) this.wQ = make(chan interface{}, writeQLen)
log.Info("%s, [session.SetWQLen] wQ{len:%d, cap:%d}", this.Stat(), len(this.wQ), cap(this.wQ))
this.lock.Unlock() this.lock.Unlock()
} }
...@@ -300,14 +303,16 @@ func (this *Session) WritePkg(pkg interface{}) error { ...@@ -300,14 +303,16 @@ func (this *Session) WritePkg(pkg interface{}) error {
const size = 64 << 10 const size = 64 << 10
rBuf := make([]byte, size) rBuf := make([]byte, size)
rBuf = rBuf[:runtime.Stack(rBuf, false)] rBuf = rBuf[:runtime.Stack(rBuf, false)]
log.Error("[session.handleLoop] panic session %s: err=%#v\n%s", this.sessionToken(), r, rBuf) log.Error("[session.WritePkg] panic session %s: err=%#v\n%s", this.sessionToken(), r, rBuf)
} }
}() }()
select { select {
case this.wQ <- pkg: case this.wQ <- pkg:
break // for possible gen a new pkg break // for possible gen a new pkg
default: default:
log.Warn("%s, [session.WritePkg] wQ{len:%d, cap:%d}", this.Stat(), len(this.wQ), cap(this.wQ))
return ErrSessionBlocked return ErrSessionBlocked
} }
...@@ -370,7 +375,7 @@ func (this *Session) handleLoop() { ...@@ -370,7 +375,7 @@ func (this *Session) handleLoop() {
grNum = atomic.AddInt32(&(this.grNum), -1) grNum = atomic.AddInt32(&(this.grNum), -1)
this.listener.OnClose(this) this.listener.OnClose(this)
log.Info("statistic{%s}, [session.handleLoop] goroutine exit now, left gr num %d", this.Stat(), grNum) log.Info("%s, [session.handleLoop] goroutine exit now, left gr num %d", this.Stat(), grNum)
this.gc() this.gc()
}() }()
...@@ -382,11 +387,15 @@ LOOP: ...@@ -382,11 +387,15 @@ LOOP:
case <-this.done: case <-this.done:
// 这个分支确保(Session)handleLoop gr在(Session)handlePackage gr之后退出 // 这个分支确保(Session)handleLoop gr在(Session)handlePackage gr之后退出
once.Do(func() { ticker.Stop() }) once.Do(func() { ticker.Stop() })
log.Info("%s, [session.handleLoop] got done signal ", this.Stat())
if atomic.LoadInt32(&(this.grNum)) == 1 { // make sure @(Session)handlePackage goroutine has been closed. if atomic.LoadInt32(&(this.grNum)) == 1 { // make sure @(Session)handlePackage goroutine has been closed.
if len(this.rQ) == 0 && len(this.wQ) == 0 {
log.Info("%s, [session.handleLoop] got done signal. Both rQ and wQ are nil.", this.Stat())
break LOOP
}
counter.Start() counter.Start()
// if time.Since(start).Nanoseconds() >= this.wait.Nanoseconds() { // if time.Since(start).Nanoseconds() >= this.wait.Nanoseconds() {
if counter.Count() > this.wait.Nanoseconds() { if counter.Count() > this.wait.Nanoseconds() {
log.Info("%s, [session.handleLoop] got done signal ", this.Stat())
break LOOP break LOOP
} }
} }
...@@ -516,6 +525,7 @@ func (this *Session) stop() { ...@@ -516,6 +525,7 @@ func (this *Session) stop() {
select { select {
case <-this.done: case <-this.done:
return return
default: default:
this.once.Do(func() { close(this.done) }) this.once.Do(func() { close(this.done) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment