Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close sizeChan to avoid memory leak. #7244

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/app/backend/handler/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type TerminalSession struct {
bound chan error
sockJSSession sockjs.Session
sizeChan chan remotecommand.TerminalSize
doneChan chan struct{}
}

// TerminalMessage is the messaging protocol between ShellController and TerminalSession.
Expand All @@ -65,15 +64,14 @@ type TerminalMessage struct {
Rows, Cols uint16
}

// TerminalSize handles pty->process resize events
// Next handles pty->process resize events
// Called in a loop from remotecommand as long as the process is running
func (t TerminalSession) Next() *remotecommand.TerminalSize {
select {
case size := <-t.sizeChan:
return &size
case <-t.doneChan:
size := <-t.sizeChan
if size.Height == 0 && size.Width == 0 {
return nil
}
return &size
}

// Read handles pty->process messages (stdin, resize)
Expand Down Expand Up @@ -161,11 +159,12 @@ func (sm *SessionMap) Set(sessionId string, session TerminalSession) {
func (sm *SessionMap) Close(sessionId string, status uint32, reason string) {
sm.Lock.Lock()
defer sm.Lock.Unlock()
err := sm.Sessions[sessionId].sockJSSession.Close(status, reason)
ses := sm.Sessions[sessionId]
err := ses.sockJSSession.Close(status, reason)
if err != nil {
log.Println(err)
}

close(ses.sizeChan)
delete(sm.Sessions, sessionId)
}

Expand Down