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
6de78d9d
Unverified
Commit
6de78d9d
authored
Sep 05, 2019
by
望哥
Committed by
GitHub
Sep 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24 from pantianying/pty_getty
Fix: cpu 100% in session.handleLoop
parents
0659b79f
82a97b4a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
session.go
session.go
+18
-18
No files found.
session.go
View file @
6de78d9d
...
@@ -88,6 +88,8 @@ type session struct {
...
@@ -88,6 +88,8 @@ type session struct {
// goroutines sync
// goroutines sync
grNum
int32
grNum
int32
// read goroutines done signal
rDone
chan
struct
{}
lock
sync
.
RWMutex
lock
sync
.
RWMutex
}
}
...
@@ -105,6 +107,8 @@ func newSession(endPoint EndPoint, conn Connection) *session {
...
@@ -105,6 +107,8 @@ func newSession(endPoint EndPoint, conn Connection) *session {
done
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
wait
:
pendingDuration
,
wait
:
pendingDuration
,
attrs
:
NewValuesContext
(
nil
),
attrs
:
NewValuesContext
(
nil
),
rDone
:
make
(
chan
struct
{}),
grNum
:
0
,
}
}
ss
.
Connection
.
setSession
(
ss
)
ss
.
Connection
.
setSession
(
ss
)
...
@@ -145,6 +149,7 @@ func (s *session) Reset() {
...
@@ -145,6 +149,7 @@ func (s *session) Reset() {
s
.
period
=
period
s
.
period
=
period
s
.
wait
=
pendingDuration
s
.
wait
=
pendingDuration
s
.
attrs
=
NewValuesContext
(
nil
)
s
.
attrs
=
NewValuesContext
(
nil
)
s
.
rDone
=
make
(
chan
struct
{})
s
.
grNum
=
0
s
.
grNum
=
0
s
.
SetWriteTimeout
(
netIOTimeout
)
s
.
SetWriteTimeout
(
netIOTimeout
)
...
@@ -487,8 +492,6 @@ func (s *session) handleLoop() {
...
@@ -487,8 +492,6 @@ func (s *session) handleLoop() {
)
)
defer
func
()
{
defer
func
()
{
var
grNum
int32
if
r
:=
recover
();
r
!=
nil
{
if
r
:=
recover
();
r
!=
nil
{
const
size
=
64
<<
10
const
size
=
64
<<
10
rBuf
:=
make
([]
byte
,
size
)
rBuf
:=
make
([]
byte
,
size
)
...
@@ -496,7 +499,7 @@ func (s *session) handleLoop() {
...
@@ -496,7 +499,7 @@ func (s *session) handleLoop() {
log
.
Errorf
(
"[session.handleLoop] panic session %s: err=%s
\n
%s"
,
s
.
sessionToken
(),
r
,
rBuf
)
log
.
Errorf
(
"[session.handleLoop] panic session %s: err=%s
\n
%s"
,
s
.
sessionToken
(),
r
,
rBuf
)
}
}
grNum
=
atomic
.
AddInt32
(
&
(
s
.
grNum
),
-
1
)
grNum
:
=
atomic
.
AddInt32
(
&
(
s
.
grNum
),
-
1
)
s
.
listener
.
OnClose
(
s
)
s
.
listener
.
OnClose
(
s
)
log
.
Info
(
"%s, [session.handleLoop] goroutine exit now, left gr num %d"
,
s
.
Stat
(),
grNum
)
log
.
Info
(
"%s, [session.handleLoop] goroutine exit now, left gr num %d"
,
s
.
Stat
(),
grNum
)
s
.
gc
()
s
.
gc
()
...
@@ -511,19 +514,17 @@ LOOP:
...
@@ -511,19 +514,17 @@ LOOP:
select
{
select
{
case
<-
s
.
done
:
case
<-
s
.
done
:
// this case branch assure the (session)handleLoop gr will exit before (session)handlePackage gr.
// this case branch assure the (session)handleLoop gr will exit before (session)handlePackage gr.
if
atomic
.
LoadInt32
(
&
(
s
.
grNum
))
==
1
{
// make sure @(session)handlePackage goroutine has been closed.
<-
s
.
rDone
if
len
(
s
.
wQ
)
==
0
{
if
len
(
s
.
wQ
)
==
0
{
log
.
Infof
(
"%s, [session.handleLoop] got done signal. wQ is nil."
,
s
.
Stat
())
log
.
Infof
(
"%s, [session.handleLoop] got done signal. wQ is nil."
,
s
.
Stat
())
break
LOOP
break
LOOP
}
}
counter
.
Start
()
counter
.
Start
()
// if time.Since(start).Nanoseconds() >= s.wait.Nanoseconds() {
// if time.Since(start).Nanoseconds() >= s.wait.Nanoseconds() {
if
counter
.
Count
()
>
s
.
wait
.
Nanoseconds
()
{
if
counter
.
Count
()
>
s
.
wait
.
Nanoseconds
()
{
log
.
Infof
(
"%s, [session.handleLoop] got done signal "
,
s
.
Stat
())
log
.
Infof
(
"%s, [session.handleLoop] got done signal "
,
s
.
Stat
())
break
LOOP
break
LOOP
}
}
}
case
outPkg
=
<-
s
.
wQ
:
case
outPkg
=
<-
s
.
wQ
:
if
flag
{
if
flag
{
if
err
=
s
.
writer
.
Write
(
s
,
outPkg
);
err
!=
nil
{
if
err
=
s
.
writer
.
Write
(
s
,
outPkg
);
err
!=
nil
{
...
@@ -568,8 +569,6 @@ func (s *session) handlePackage() {
...
@@ -568,8 +569,6 @@ func (s *session) handlePackage() {
)
)
defer
func
()
{
defer
func
()
{
var
grNum
int32
if
r
:=
recover
();
r
!=
nil
{
if
r
:=
recover
();
r
!=
nil
{
const
size
=
64
<<
10
const
size
=
64
<<
10
rBuf
:=
make
([]
byte
,
size
)
rBuf
:=
make
([]
byte
,
size
)
...
@@ -577,7 +576,8 @@ func (s *session) handlePackage() {
...
@@ -577,7 +576,8 @@ func (s *session) handlePackage() {
log
.
Errorf
(
"[session.handlePackage] panic session %s: err=%s
\n
%s"
,
s
.
sessionToken
(),
r
,
rBuf
)
log
.
Errorf
(
"[session.handlePackage] panic session %s: err=%s
\n
%s"
,
s
.
sessionToken
(),
r
,
rBuf
)
}
}
grNum
=
atomic
.
AddInt32
(
&
(
s
.
grNum
),
-
1
)
close
(
s
.
rDone
)
grNum
:=
atomic
.
AddInt32
(
&
(
s
.
grNum
),
-
1
)
log
.
Infof
(
"%s, [session.handlePackage] gr will exit now, left gr num %d"
,
s
.
sessionToken
(),
grNum
)
log
.
Infof
(
"%s, [session.handlePackage] gr will exit now, left gr num %d"
,
s
.
sessionToken
(),
grNum
)
s
.
stop
()
s
.
stop
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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