Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
848c9843
Commit
848c9843
authored
Sep 10, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add logs
parent
5702c16e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
session.go
session.go
+13
-3
No files found.
session.go
View file @
848c9843
...
@@ -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
)
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment