From 91106f3c492180139c81c4acfa2061f5b08bccbe Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 12 Jan 2021 20:59:30 +0000 Subject: [PATCH] Prevent terminal msg from being overwritten to later concurrent writes --- internal/multiplex/session.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/multiplex/session.go b/internal/multiplex/session.go index 504298d..f530f19 100644 --- a/internal/multiplex/session.go +++ b/internal/multiplex/session.go @@ -73,7 +73,8 @@ type Session struct { closed uint32 - terminalMsg atomic.Value + terminalMsgSetter sync.Once + terminalMsg string // the max size passed to Write calls before it splits it into multiple frames // i.e. the max size a piece of data can fit into a Frame.Payload @@ -263,16 +264,13 @@ func (sesh *Session) recvDataFromRemote(data []byte) error { } func (sesh *Session) SetTerminalMsg(msg string) { - sesh.terminalMsg.Store(msg) + sesh.terminalMsgSetter.Do(func() { + sesh.terminalMsg = msg + }) } func (sesh *Session) TerminalMsg() string { - msg := sesh.terminalMsg.Load() - if msg != nil { - return msg.(string) - } else { - return "" - } + return sesh.terminalMsg } func (sesh *Session) closeSession() error {