diff --git a/internal/session/handle_close.go b/internal/session/handle_close.go index e25f3177..9d7dc673 100644 --- a/internal/session/handle_close.go +++ b/internal/session/handle_close.go @@ -26,8 +26,6 @@ func (s *Session) handleClose(ctx context.Context, tag string, cmd *proto.Close, return err } - s.name = "" - ch <- response.Ok(tag).WithMessage("CLOSE") return nil diff --git a/internal/session/handle_examine.go b/internal/session/handle_examine.go index 230b116e..0cc4a7e4 100644 --- a/internal/session/handle_examine.go +++ b/internal/session/handle_examine.go @@ -38,8 +38,6 @@ func (s *Session) handleExamine(ctx context.Context, tag string, cmd *proto.Exam ch <- response.Ok().WithItems(response.ItemUnseen(unseen[0])) } - s.name = mailbox.Name() - return nil }); err != nil { return err diff --git a/internal/session/handle_select.go b/internal/session/handle_select.go index e52e5313..eddcf716 100644 --- a/internal/session/handle_select.go +++ b/internal/session/handle_select.go @@ -39,8 +39,6 @@ func (s *Session) handleSelect(ctx context.Context, tag string, cmd *proto.Selec ch <- response.Ok().WithItems(response.ItemUnseen(unseen[0])).WithMessage("Unseen messages") } - s.name = mailbox.Name() - return nil }); err != nil { return err diff --git a/internal/session/handle_unselect.go b/internal/session/handle_unselect.go index bec65b11..fc4cfa5e 100644 --- a/internal/session/handle_unselect.go +++ b/internal/session/handle_unselect.go @@ -13,8 +13,6 @@ func (s *Session) handleUnselect(ctx context.Context, tag string, cmd *proto.Uns return err } - s.name = "" - ch <- response.Ok(tag).WithMessage("UNSELECT") return nil diff --git a/internal/session/logger.go b/internal/session/logger.go index 7a8ff342..c9b0caa0 100644 --- a/internal/session/logger.go +++ b/internal/session/logger.go @@ -6,18 +6,14 @@ import ( "strings" ) -func writeLog(w io.Writer, leader, sessionID, mailbox, line string) { +func writeLog(w io.Writer, leader, sessionID, line string) { line = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(strings.TrimSpace(line), "\r", `\r`), "\n", `\n`), "\t", `\t`) - if len(mailbox) > maxNameLength { - mailbox = mailbox[:maxNameLength] + "..." - } - if len(line) > maxLineLength { line = line[:maxLineLength] + "..." } - if _, err := fmt.Fprintf(w, "%v[%v][%v]: %v\n", leader, sessionID, mailbox, line); err != nil { + if _, err := fmt.Fprintf(w, "%v[%v]: %v\n", leader, sessionID, line); err != nil { panic(err) } } diff --git a/internal/session/session.go b/internal/session/session.go index 1ce483a6..35bde41c 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -37,9 +37,6 @@ type Session struct { // state manages state of the authorized backend for this session. state *backend.State - // name holds the name of the currently selected mailbox, if any. - name string - // userLock protects the session's user object. userLock sync.Mutex @@ -202,15 +199,7 @@ func (s *Session) logIncoming(line string) { return } - var name string - - if s.name != "" { - name = s.name - } else { - name = "--" - } - - writeLog(s.inLogger, "C", strconv.Itoa(s.sessionID), name, line) + writeLog(s.inLogger, "C", strconv.Itoa(s.sessionID), line) } func (s *Session) logOutgoing(line string) { @@ -218,15 +207,7 @@ func (s *Session) logOutgoing(line string) { return } - var name string - - if s.name != "" { - name = s.name - } else { - name = "--" - } - - writeLog(s.outLogger, "S", strconv.Itoa(s.sessionID), name, line) + writeLog(s.outLogger, "S", strconv.Itoa(s.sessionID), line) } func (s *Session) done(ctx context.Context) { diff --git a/tests/full_state_test.go b/tests/full_state_test.go index 71a74f31..44683e41 100644 --- a/tests/full_state_test.go +++ b/tests/full_state_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "runtime/pprof" + "sync/atomic" "testing" "time" @@ -99,11 +100,11 @@ func TestReceptionOnIdle(t *testing.T) { require.Equal(t, uint32(0), status.Messages, "Expected message count does not match") // prepare to stop idling. - stopped := false + stopped := int32(0) stop := make(chan struct{}) done := make(chan error, 1) // Create a channel to receive mailbox updates. - updates := make(chan client.Update) + updates := make(chan client.Update, 100) c.Updates = updates // idling. @@ -111,7 +112,7 @@ func TestReceptionOnIdle(t *testing.T) { labels := pprof.Labels("test", "client", "idling", "idle") pprof.Do(context.Background(), labels, func(_ context.Context) { defer func() { - stopped = true + atomic.StoreInt32(&stopped, 1) }() done <- c.Idle(stop, nil) }) @@ -137,7 +138,7 @@ func TestReceptionOnIdle(t *testing.T) { var existsUpdate uint32 = 0 var recentUpdate uint32 = 0 - for !stopped { + for atomic.LoadInt32(&stopped) == 0 { select { case update := <-updates: boxUpdate, ok := update.(*client.MailboxUpdate)