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
888d134d
Commit
888d134d
authored
Mar 02, 2020
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Imp: close connection asynchronously in session.gc
parent
5334e7d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
15 deletions
+35
-15
session.go
session.go
+35
-15
No files found.
session.go
View file @
888d134d
...
...
@@ -91,7 +91,7 @@ type session struct {
// done
wait
time
.
Duration
once
sync
.
Once
once
*
sync
.
Once
done
chan
struct
{}
// attribute
...
...
@@ -115,6 +115,7 @@ func newSession(endPoint EndPoint, conn Connection) *session {
period
:
period
,
once
:
&
sync
.
Once
{},
done
:
make
(
chan
struct
{}),
wait
:
pendingDuration
,
attrs
:
gxcontext
.
NewValuesContext
(
nil
),
...
...
@@ -153,14 +154,15 @@ func newWSSession(conn *websocket.Conn, endPoint EndPoint) Session {
}
func
(
s
*
session
)
Reset
()
{
s
.
name
=
defaultSessionName
s
.
once
=
sync
.
Once
{}
s
.
done
=
make
(
chan
struct
{})
s
.
period
=
period
s
.
wait
=
pendingDuration
s
.
attrs
=
gxcontext
.
NewValuesContext
(
nil
)
s
.
rDone
=
make
(
chan
struct
{})
s
.
grNum
=
0
*
s
=
session
{
name
:
defaultSessionName
,
once
:
&
sync
.
Once
{},
done
:
make
(
chan
struct
{}),
period
:
period
,
wait
:
pendingDuration
,
attrs
:
gxcontext
.
NewValuesContext
(
nil
),
rDone
:
make
(
chan
struct
{}),
}
s
.
SetWriteTimeout
(
netIOTimeout
)
s
.
SetReadTimeout
(
netIOTimeout
)
...
...
@@ -360,6 +362,10 @@ func (s *session) RemoveAttribute(key interface{}) {
}
func
(
s
*
session
)
sessionToken
()
string
{
if
s
.
IsClosed
()
||
s
.
Connection
==
nil
{
return
"session-closed"
}
return
fmt
.
Sprintf
(
"{%s:%s:%d:%s<->%s}"
,
s
.
name
,
s
.
EndPoint
()
.
EndPointType
(),
s
.
ID
(),
s
.
LocalAddr
(),
s
.
RemoteAddr
())
}
...
...
@@ -663,7 +669,9 @@ func (s *session) handlePackage() {
s
.
stop
()
if
err
!=
nil
{
log
.
Errorf
(
"%s, [session.handlePackage] error:%+v"
,
s
.
sessionToken
(),
err
)
s
.
listener
.
OnError
(
s
,
err
)
if
s
!=
nil
||
s
.
listener
!=
nil
{
s
.
listener
.
OnError
(
s
,
err
)
}
}
}()
...
...
@@ -730,12 +738,12 @@ func (s *session) handleTCPPackage() error {
if
netError
,
ok
=
perrors
.
Cause
(
err
)
.
(
net
.
Error
);
ok
&&
netError
.
Timeout
()
{
break
}
log
.
Errorf
(
"%s, [session.conn.read] = error:%+v"
,
s
.
sessionToken
(),
err
)
if
perrors
.
Cause
(
err
)
==
io
.
EOF
{
err
=
nil
exit
=
true
break
}
log
.
Errorf
(
"%s, [session.conn.read] = error:%+v"
,
s
.
sessionToken
(),
err
)
exit
=
true
}
break
...
...
@@ -759,7 +767,7 @@ func (s *session) handleTCPPackage() error {
// handle case 1
if
err
!=
nil
{
log
.
Warnf
(
"%s, [session.handleTCPPackage] = len{%d}, error:%+v"
,
s
.
sessionToken
(),
pkgLen
,
err
)
s
.
sessionToken
(),
pkgLen
,
perrors
.
WithStack
(
err
)
)
exit
=
true
break
}
...
...
@@ -877,7 +885,7 @@ func (s *session) handleWSPackage() error {
}
if
err
!=
nil
{
log
.
Warnf
(
"%s, [session.handleWSPackage] = error{%+s}"
,
s
.
sessionToken
(),
err
)
s
.
sessionToken
(),
perrors
.
WithStack
(
err
)
)
return
perrors
.
WithStack
(
err
)
}
s
.
UpdateActive
()
...
...
@@ -924,16 +932,28 @@ func (s *session) stop() {
}
func
(
s
*
session
)
gc
()
{
var
(
wQ
chan
interface
{}
conn
Connection
)
s
.
lock
.
Lock
()
if
s
.
attrs
!=
nil
{
s
.
attrs
=
nil
if
s
.
wQ
!=
nil
{
close
(
s
.
wQ
)
wQ
=
s
.
wQ
s
.
wQ
=
nil
}
s
.
Connection
.
close
((
int
)((
int64
)(
s
.
wait
)))
conn
=
s
.
Connection
}
s
.
lock
.
Unlock
()
go
func
()
{
if
wQ
!=
nil
{
conn
.
close
((
int
)((
int64
)(
s
.
wait
)))
close
(
wQ
)
}
}()
}
// Close will be invoked by NewSessionCallback(if return error is not 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