You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/04/10 16:31:06 UTC

[GitHub] [dubbo-getty] watermelo commented on a change in pull request #56: Ftr: delete session.handleLoop

watermelo commented on a change in pull request #56:
URL: https://github.com/apache/dubbo-getty/pull/56#discussion_r611062237



##########
File path: session.go
##########
@@ -479,56 +498,12 @@ func (s *session) run() {
 		return
 	}
 
-	// start read/write gr
-	atomic.AddInt32(&(s.grNum), 2)
-	go s.handleLoop()
-	go s.handlePackage()
-}
-
-func (s *session) handleLoop() {
-	var (
-		wsFlag  bool
-		wsConn  *gettyWSConn
-		counter gxtime.CountWatch
-	)
-
-	defer func() {
-		if r := recover(); r != nil {
-			const size = 64 << 10
-			rBuf := make([]byte, size)
-			rBuf = rBuf[:runtime.Stack(rBuf, false)]
-			log.Errorf("[session.handleLoop] panic session %s: err=%s\n%s", s.sessionToken(), r, rBuf)
-		}
-
-		grNum := atomic.AddInt32(&(s.grNum), -1)
-		s.listener.OnClose(s)
-		log.Infof("%s, [session.handleLoop] goroutine exit now, left gr num %d", s.Stat(), grNum)
-		s.gc()
-	}()
-
-	wsConn, wsFlag = s.Connection.(*gettyWSConn)
-LOOP:
-	for {
-		select {
-		case <-s.done:
-			// this case branch assure the (session)handleLoop gr will exit after (session)handlePackage gr.
-			<-s.rDone
-			counter.Start()
-			if counter.Count() > s.wait.Nanoseconds() {
-				log.Infof("%s, [session.handleLoop] got done signal ", s.Stat())
-				break LOOP
-			}
-
-		case <-wheel.After(s.period):
-			if wsFlag {
-				err := wsConn.writePing()
-				if err != nil {
-					log.Warnf("wsConn.writePing() = error:%+v", perrors.WithStack(err))
-				}
-			}
-			s.listener.OnCron(s)
-		}
+	s.grNum.Add(1)
+	if _, err := defaultTimerWheel.AddTimer(sessionTimerLoop, gxtime.TimerLoop, s.period, s); err != nil {

Review comment:
       内存泄露,如果 session 关闭,该 session 的 `sessionTimerLoop` 还会一直被执行下去。需要清理资源




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org