go-imap/v2 doesn't support context cancellation for in-flight requests #2

Closed
opened 2026-05-10 23:29:25 +02:00 by heiko · 1 comment
Owner

Ctrl+C (SIGINT) cannot immediately abort in-flight IMAP network requests because the go-imap/v2 library doesn't expose context parameters in its command methods.

Current Behavior

  • ✓ New message processing stops immediately
  • ✓ IDLE listener exits gracefully
  • ✗ Hung network requests block indefinitely until timeout

Solutions to Investigate

  1. Switch IMAP library to one with context support
  2. Add per-operation timeouts
  3. Use goroutine killables for requests
  4. Close connection on signal, forcing request failures
  • internal/imap/client.go - Methods without context support
  • cmd/scanner/main.go - Signal handling and context setup

Notes

The limitation is fundamental to the go-imap/v2 library design, not a bug in our code.

Ctrl+C (SIGINT) cannot immediately abort in-flight IMAP network requests because the go-imap/v2 library doesn't expose context parameters in its command methods. ## Current Behavior - ✓ New message processing stops immediately - ✓ IDLE listener exits gracefully - ✗ Hung network requests block indefinitely until timeout ## Solutions to Investigate 1. Switch IMAP library to one with context support 2. Add per-operation timeouts 3. Use goroutine killables for requests 4. Close connection on signal, forcing request failures ## Related Code - `internal/imap/client.go` - Methods without context support - `cmd/scanner/main.go` - Signal handling and context setup ## Notes The limitation is fundamental to the go-imap/v2 library design, not a bug in our code.
heiko changed title from BUG: go-imap/v2 doesn't support context cancellation for in-flight requests to go-imap/v2 doesn't support context cancellation for in-flight requests 2026-05-10 23:37:04 +02:00
Author
Owner

Do we really need an IMAP library? Can't we implement the some IMAP interactions we need in a more generic way. Isn't there a more generic library for text based protocols, like IMAP, SMTP, ...? Or can we create one?

Do we really need an IMAP library? Can't we implement the some IMAP interactions we need in a more generic way. Isn't there a more generic library for text based protocols, like IMAP, SMTP, ...? Or can we create one?
heiko closed this issue 2026-05-12 00:15:34 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IUS/xr-invoiced#2
No description provided.