Skip to content

Commit

Permalink
client: cancel pending literal writes after status response
Browse files Browse the repository at this point in the history
Fixes #113
  • Loading branch information
emersion committed Jun 8, 2019
1 parent c5d9e14 commit 00bb006
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Client struct {
serverName string

loggedOut chan struct{}
continues chan<- bool
upgrading bool

handlers []responses.Handler
Expand Down Expand Up @@ -231,6 +232,11 @@ func (c *Client) execute(cmdr imap.Commander, h responses.Handler) (*imap.Status
// Wait for upgrade to finish.
c.conn.Wait()
}
// Cancel any pending literal write
select {
case c.continues <- false:
default:
}
return errUnregisterHandler
}

Expand Down Expand Up @@ -322,11 +328,11 @@ func (c *Client) Execute(cmdr imap.Commander, h responses.Handler) (*imap.Status
return c.execute(cmdr, h)
}

func (c *Client) handleContinuationReqs(continues chan<- bool) {
func (c *Client) handleContinuationReqs() {
c.registerHandler(responses.HandlerFunc(func(resp imap.Resp) error {
if _, ok := resp.(*imap.ContinuationReq); ok {
go func() {
continues <- true
c.continues <- true
}()
return nil
}
Expand Down Expand Up @@ -572,11 +578,12 @@ func New(conn net.Conn) (*Client, error) {
c := &Client{
conn: imap.NewConn(conn, r, w),
loggedOut: make(chan struct{}),
continues: continues,
state: imap.ConnectingState,
ErrorLog: log.New(os.Stderr, "imap/client: ", log.LstdFlags),
}

c.handleContinuationReqs(continues)
c.handleContinuationReqs()
c.handleUnilateral()
err := c.handleGreetAndStartReading()
return c, err
Expand Down

0 comments on commit 00bb006

Please sign in to comment.