go-imap: Deadlock when executing commands in a loop

@emersion Hello, I want to count number of messages in folders(mailboxes). I made infinity loop only for tests.

It’s look like my problem from IDLE, that last command is not finished and next is ignored causing to block.

It’s code from example, I only added code inside for reading from channel.

    for {

        c, err := client.Dial("localhost:143")
        if err != nil {
            log.Fatal(err)
        }
        log.Println("Connected")

        if err := c.Login("user", "password"); err != nil {
            panic(err)
        }
        log.Println("Logged in")

        // List mailboxes
        mailboxes := make(chan *imap.MailboxInfo, 10)
        go func() {
        if err := c.List("", "*", mailboxes); err != nil {
                log.Fatal(err)
            }
        }()

        log.Println("Mailboxes:")
        for m := range mailboxes {
            log.Println("* " + m.Name)

            mbox, err := c.Select(m.Name, true)
            if err != nil {
                log.Println("Error", err)
                return
            }
            fmt.Println(m.Name, " + ", mbox.Messages)
            c.Close()

        }

        c.Logout()
    }
E336w OK [READ-ONLY] Examine completed (0.000 secs).
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS ()] Read-only mailbox.
* 26 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1484216700] UIDs valid
* OK [UIDNEXT 27] Predicted next UID
* OK [NOMODSEQ] No permanent modsequences
36w OK [READ-ONLY] Examine completed (0.000 secs).
imap/client: 2017/02/23 11:00:15 response has not been handled: &{* OK NOMODSEQ [] No permanent modsequences}
lE336w EXAMINE Sent
36w EXAMINE Sent

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@emersion I tested this again in go-imap/v1 and go-imap-idle/v1, and can no longer reproduce this issue. Nice!

The response handling in the client is a mess. I’d like to change that for v1, and maybe use callbacks instead of channels. Need to check if that leads to race conditions though.