fix: add TLS session resumption#1304
Conversation
| if a.ClientSessionCache == nil { | ||
| a.ClientSessionCache = tls.NewLRUClientSessionCache(64) | ||
| } | ||
| } |
There was a problem hiding this comment.
If the same account is used concurrently, for example by a background IMAP reconnect and an SMTP send, this can cause a data race during the first cache initialization. It would be better to initialize the cache up front when loading/creating the account, or protect it with a mutex / sync.Once.
|
@andrinoff Need to verify the expected behavior:
I'm not entirely sure if this is implemented correctly or not. |
I've verified the behavior in both scenarios:
|
|
i will check it out tomorrow evening, im busy |
|
I tried to handle the race condition as @FromSi suggested above, but tests failed with:
I moved to a pointer-based approach by extracting As a temporary fix I added Is there a cleaner approach here? |
| ClientSessionCache: account.GetClientSessionCache(), | ||
| VerifyConnection: func(cs tls.ConnectionState) error { | ||
| log.Printf("IMAP TLS connection resumed: %t", cs.DidResume) | ||
| return nil | ||
| }, |
There was a problem hiding this comment.
this will fire on every connection
| ClientSessionCache: account.GetClientSessionCache(), | ||
| VerifyConnection: func(cs tls.ConnectionState) error { | ||
| log.Printf("SMTP TLS connection resumed: %t", cs.DidResume) | ||
| return nil | ||
| }, |
| VerifyConnection: func(cs tls.ConnectionState) error { | ||
| log.Printf("SMTP TLS connection resumed: %t", cs.DidResume) | ||
| return nil | ||
| }, |
|
@mavonx fix the debug logging.
this should not be the experience |
|
debug logging could be done by having an env variable (set with |
|
actually, use #1311, just merged, and rebased the branch |
Regarding the nil guard — adding a nil check in Is that acceptable, or do you have a preferred approach to avoid touching the test? |
|
ok, that's fine then. do the log, i'll resolve the comment |

What?
Configured
TLSsession resumption forIMAPandSMTP.Why?
Reduce reconnect latency by avoiding full
TLShandshakes.Closes #1174