mirror of https://github.com/v2ray/v2ray-core
force close session manage when main connection is finished
parent
81d840699a
commit
2cf809021b
|
@ -121,6 +121,7 @@ func (m *Client) monitor() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-m.ctx.Done():
|
case <-m.ctx.Done():
|
||||||
|
m.sessionManager.Close()
|
||||||
m.inboundRay.InboundInput().Close()
|
m.inboundRay.InboundInput().Close()
|
||||||
m.inboundRay.InboundOutput().CloseError()
|
m.inboundRay.InboundOutput().CloseError()
|
||||||
return
|
return
|
||||||
|
@ -302,6 +303,8 @@ func handle(ctx context.Context, s *Session, output buf.Writer) {
|
||||||
func (w *ServerWorker) run(ctx context.Context) {
|
func (w *ServerWorker) run(ctx context.Context) {
|
||||||
input := w.outboundRay.OutboundInput()
|
input := w.outboundRay.OutboundInput()
|
||||||
reader := NewReader(input)
|
reader := NewReader(input)
|
||||||
|
|
||||||
|
defer w.sessionManager.Close()
|
||||||
L:
|
L:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -74,10 +74,26 @@ func (m *SessionManager) CloseIfNoSession() bool {
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
|
|
||||||
|
if m.closed {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if len(m.sessions) == 0 {
|
if len(m.sessions) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.closed = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SessionManager) Close() {
|
||||||
|
m.RLock()
|
||||||
|
defer m.RUnlock()
|
||||||
|
|
||||||
|
if m.closed {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
m.closed = true
|
m.closed = true
|
||||||
|
|
||||||
for _, s := range m.sessions {
|
for _, s := range m.sessions {
|
||||||
|
@ -86,8 +102,6 @@ func (m *SessionManager) CloseIfNoSession() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.sessions = make(map[uint16]*Session)
|
m.sessions = make(map[uint16]*Session)
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
|
Loading…
Reference in New Issue