Necoro / feed2imap-go

A software to convert rss feeds into mails.
GNU General Public License v2.0
53 stars 7 forks source link

panic: send on closed channel #97

Closed nomeata closed 1 year ago

nomeata commented 1 year ago

Every two days or so I get a email from cron with

panic: send on closed channel

goroutine 213 [running]:
github.com/Necoro/feed2imap-go/internal/imap.(*Client).connect(0x400040a090, {{0x40001912b0, 0x5}, {0x40000c2738, 0x18}, {0x40001912d8, 0x8}, {0x4000191310, 0x10}, {0x5e228a, ...}, ...})
    github.com/Necoro/feed2imap-go/internal/imap/client.go:72 +0x324
github.com/Necoro/feed2imap-go/internal/imap.Connect.func2(0x400034a540?)
    github.com/Necoro/feed2imap-go/internal/imap/imap.go:46 +0x60
created by github.com/Necoro/feed2imap-go/internal/imap.Connect
    github.com/Necoro/feed2imap-go/internal/imap/imap.go:45 +0x4ac

Not sure what to do about it, though. I guess the error could be caught and reported more prettily “E.g. saying which server failed during which operation”.

An error should probably be reported so that I know if it keeps failing.

However, a spurious error like this isn’t much to worry about; maybe feed2imap-go could retry once or twice before bugging the user?

Necoro commented 1 year ago

Short background: feed2imap-go opens multiple connections to the IMAP-server, so that whenever a feed has finished pulling, parsing and checking against the cache, it can grab a connection and make it do its bidding.

At first, only one connection is established (to check that server is reachable, credentials fit, etc). The other connections are then opened in the background (and added to the pool as they come).

From what I can figure, feed2imap-go was still in the process of establishing those connections when the main program was done and issued the Disconnect-command. Reason: The error says that the channel that adds new connections to the connection pool has been closed.

So, this is indeed a bug: feed2imap-go should handle this more graceful.

Could you check running with the -v flag to see whether this diagnosis fits? In regular cases you should see 5 "connected" messages and one "disconnected". In your error case there should be less than 5 "connected" and the error message should be around the "Disconnect"

I also opened #98 to make the number of parallel connections configurable, so that it can be reduced when the mail server does not support multiple connections.

nomeata commented 1 year ago

This only happens rarely, so running the command with -v on the command line I only see the regular behavior you describe, unfortunately.