diff options
author | Robin Jarry <robin@jarry.cc> | 2023-07-14 23:42:19 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-07-15 17:09:49 +0200 |
commit | 7a674312b6f006be7c1241b10cf9063841aa1d9c (patch) | |
tree | f40e45f715611847bbb2355a902ebc940ada823d /worker/jmap | |
parent | a791da7ba45d44b5e9d66d67558fc725977b7345 (diff) | |
download | aerc-7a674312b6f006be7c1241b10cf9063841aa1d9c.tar.gz |
jmap: fix crash when opening multiple instances
Fix the following error when opening another aerc instance with the same
jmap account:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x9a1ffd]
git.sr.ht/~rjarry/aerc/worker/jmap/cache.(*JMAPCache).get(0x99d08e?, {0xbc3c1a?, 0xc00003a160?})
git.sr.ht/~rjarry/aerc/worker/jmap/cache/cache.go:47 +0x1d
git.sr.ht/~rjarry/aerc/worker/jmap/cache.(*JMAPCache).GetSession(0xc00052a030?)
git.sr.ht/~rjarry/aerc/worker/jmap/cache/session.go:8 +0x29
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).handleConnect(0xc00055e180, 0x0?)
git.sr.ht/~rjarry/aerc/worker/jmap/connect.go:29 +0xd3
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).handleMessage(0xc000311500?, {0xcc8b00?, 0xc0001fcff0?})
git.sr.ht/~rjarry/aerc/worker/jmap/worker.go:114 +0x9f
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).Run(0xc00055e180)
git.sr.ht/~rjarry/aerc/worker/jmap/worker.go:177 +0x10c
git.sr.ht/~rjarry/aerc/widgets.NewAccountView.func3()
git.sr.ht/~rjarry/aerc/widgets/account.go:110 +0x65
created by git.sr.ht/~rjarry/aerc/widgets.NewAccountView
git.sr.ht/~rjarry/aerc/widgets/account.go:103 +0x518
Do not return an error if the leveldb cannot be opened, log a message
and fallback on the in-memory cache.
Fixes: be0bfc1ae28b ("worker: add jmap support")
Reported-by: Tim Culverhouse <tim@timculverhouse.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'worker/jmap')
-rw-r--r-- | worker/jmap/cache/cache.go | 15 | ||||
-rw-r--r-- | worker/jmap/configure.go | 16 |
2 files changed, 15 insertions, 16 deletions
diff --git a/worker/jmap/cache/cache.go b/worker/jmap/cache/cache.go index ab264744..07d23493 100644 --- a/worker/jmap/cache/cache.go +++ b/worker/jmap/cache/cache.go @@ -5,6 +5,7 @@ import ( "os" "path" + "git.sr.ht/~rjarry/aerc/log" "github.com/mitchellh/go-homedir" "github.com/syndtr/goleveldb/leveldb" ) @@ -15,29 +16,31 @@ type JMAPCache struct { blobsDir string } -func NewJMAPCache(state, blobs bool, accountName string) (*JMAPCache, error) { +func NewJMAPCache(state, blobs bool, accountName string) *JMAPCache { c := new(JMAPCache) cacheDir, err := os.UserCacheDir() if err != nil { cacheDir, err = homedir.Expand("~/.cache") if err != nil { - return nil, err + log.Errorf("homedir.Expand: %s", err) + cacheDir = "" } } - if state { + if state && cacheDir != "" { dir := path.Join(cacheDir, "aerc", accountName, "state") _ = os.MkdirAll(dir, 0o700) c.file, err = leveldb.OpenFile(dir, nil) if err != nil { - return nil, err + log.Errorf("failed to open goleveldb: %s", err) + c.mem = make(map[string][]byte) } } else { c.mem = make(map[string][]byte) } - if blobs { + if blobs && cacheDir != "" { c.blobsDir = path.Join(cacheDir, "aerc", accountName, "blobs") } - return c, nil + return c } var notfound = errors.New("key not found") diff --git a/worker/jmap/configure.go b/worker/jmap/configure.go index f57dbd73..dd6f3f36 100644 --- a/worker/jmap/configure.go +++ b/worker/jmap/configure.go @@ -11,6 +11,12 @@ import ( ) func (w *JMAPWorker) handleConfigure(msg *types.Configure) error { + w.config.cacheState = parseBool(msg.Config.Params["cache-state"]) + w.config.cacheBlobs = parseBool(msg.Config.Params["cache-blobs"]) + w.config.useLabels = parseBool(msg.Config.Params["use-labels"]) + w.cache = cache.NewJMAPCache( + w.config.cacheState, w.config.cacheBlobs, msg.Config.Name) + u, err := url.Parse(msg.Config.Source) if err != nil { return err @@ -36,9 +42,6 @@ func (w *JMAPWorker) handleConfigure(msg *types.Configure) error { w.config.endpoint = u.String() w.config.account = msg.Config - w.config.cacheState = parseBool(msg.Config.Params["cache-state"]) - w.config.cacheBlobs = parseBool(msg.Config.Params["cache-blobs"]) - w.config.useLabels = parseBool(msg.Config.Params["use-labels"]) w.config.allMail = msg.Config.Params["all-mail"] if w.config.allMail == "" { w.config.allMail = "All mail" @@ -51,13 +54,6 @@ func (w *JMAPWorker) handleConfigure(msg *types.Configure) error { w.config.serverPing = dur } - c, err := cache.NewJMAPCache( - w.config.cacheState, w.config.cacheBlobs, msg.Config.Name) - if err != nil { - return err - } - w.cache = c - return nil } |