Skip to content

Commit

Permalink
fix: Do not delete ConnMetadata store with SELECT or EXAMINE
Browse files Browse the repository at this point in the history
This patch adds `State.cleanupConnMetadata()` to cleanup the metadata
rather than relying on `State.close()`. If present in the letter the
state is also cleaned up when the SELECT or EXAMINE commands are
executed, which is not what we want.
  • Loading branch information
LBeernaertProton committed Jun 14, 2022
1 parent 1d7d456 commit e945515
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/backend/mailbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,9 @@ func (m *Mailbox) Flush(ctx context.Context, permitExpunge bool) ([]response.Res
}

func (m *Mailbox) Close(ctx context.Context) error {
if err := m.state.deleteConnMetadata(); err != nil {
return err
}

return m.state.close(ctx, m.tx)
}
12 changes: 8 additions & 4 deletions internal/backend/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,21 @@ func (state *State) updateMessageID(oldID, newID string) error {
return nil
}

func (state *State) deleteConnMetadata() error {
if err := state.remote.DeleteConnMetadataStore(state.metadataID); err != nil {
return fmt.Errorf("failed to delete conn metadata store: %w", err)
}

return nil
}

func (state *State) close(ctx context.Context, tx *ent.Tx) error {
if state.snap != nil && state.pool.hasSnap(state.snap) {
if err := state.pool.expungeSnap(ctx, tx, state.snap); err != nil {
return err
}
}

if err := state.remote.DeleteConnMetadataStore(state.metadataID); err != nil {
return fmt.Errorf("failed to delete conn metadata store: %w", err)
}

state.snap = nil

state.res = nil
Expand Down
8 changes: 8 additions & 0 deletions internal/backend/user_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (user *user) closeState(ctx context.Context, state *State) error {
user.statesLock.Lock()
defer user.statesLock.Unlock()

if err := state.deleteConnMetadata(); err != nil {
return err
}

if err := state.close(ctx, tx); err != nil {
return fmt.Errorf("failed to close state: %w", err)
}
Expand All @@ -47,6 +51,10 @@ func (user *user) closeStates(ctx context.Context) error {
defer user.statesLock.Unlock()

for stateID, state := range user.states {
if err := state.deleteConnMetadata(); err != nil {
return err
}

if err := state.close(ctx, tx); err != nil {
return fmt.Errorf("failed to close state: %w", err)
}
Expand Down

0 comments on commit e945515

Please sign in to comment.