aboutsummaryrefslogtreecommitdiffstats
path: root/worker/types/worker.go
Commit message (Collapse)AuthorAgeFilesLines
* log: log account name in worker message logsTim Culverhouse2023-01-291-8/+8
| | | | | | | Add account name to log of all Post/Process Message/Action logs. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* lint: add missing panic handlers in goroutinesRobin Jarry2023-01-061-0/+1
| | | | | | | | These issues were all reported by the new custom analyzer introduced in previous commit. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* model: change flags array to bitmaskRobin Jarry2023-01-041-1/+1
| | | | | | | Using a list of integers is not optimal. Use a bit mask instead. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* logging: rename package to logRobin Jarry2022-12-021-9/+9
| | | | | | | | | | Use the same name than the builtin "log" package. That way, we do not risk logging in the wrong place. Suggested-by: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* logging: homogenize levelsRobin Jarry2022-12-021-8/+8
| | | | | | | | | | | | | | | | | | The main goal is to ensure that by default, the log file (if configured) does not grow out of proportions. Most of the logging messages in aerc are actually for debugging and/or trace purposes. Define clear rules for logging levels. Enforce these rules everywhere. After this patch, here is what the log file looks like after starting up with a single account: INFO 2022/11/24 20:26:16.147164 aerc.go:176: Starting up version 0.13.0-100-g683981479c60 (go1.18.7 amd64 linux) INFO 2022/11/24 20:26:17.546448 account.go:254: [work] connected. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* aerc: use single event loopTim Culverhouse2022-10-071-6/+8
| | | | | | | | | Combine tcell events with WorkerMessages to better synchronize state with IO and UI. Remove Tick loop for rendering. Use events to trigger renders. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* worker: use container/list as job queueTim Culverhouse2022-10-041-2/+41
| | | | | | | | | | | | | | | | | The worker uses a buffered channel to queue tasks. Buffered channels are effective at FIFO, but are prone to blocking. The design of aerc is such that the UI must always accept a response from the backends, and the backends must always accept a request from the UI. By using buffered channels for both of these communication channels, a deadlock will occur. Break the chain by using a doubly linked list (container/list from the standard library) to queue tasks for the worker. Essentially, this is an infinitely buffered channel - but more memory efficient as it can change size dynamically. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
* worker: do not lock while callbacks are runningTim Culverhouse2022-09-291-4/+10
| | | | | | | | | | | | | Commit 716ade896871 ("worker: lock access to callback maps") introduced locks to the worker callback maps. The locks also locked the processing of the callback, which had the unintended side effect of deadlocking the worker if any callbacks attempted to post a new action or message. Refactor the locks to only lock the worker while accessing the maps. Fixes: 716ade896871 ("worker: lock access to callback maps") Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* worker: lock access to callback mapsTim Culverhouse2022-09-261-0/+11
| | | | | | | | | Worker callbacks are inherently set and called from different goroutines. Protect access to all callback maps with a mutex. Signed-off-by: Moritz Poldrack <moritz@poldrack.dev> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* backends: send MessageInfoError on header fetching errorTim Culverhouse2022-09-251-0/+15
| | | | | | | | | | | | | | | | | | | | | When an error is encountered fetching a header, the backends respond with a type.Error worker message. On receipt of this message, the UI deletes all pending headers. The headers are all requested again as they remain on the screen, resulting in an infinite request loop - and an infinite logging loop. The user only ever sees the spinner unless they check the logs. A previous commit intended to fix this, however it introduced a regression where any message that was part of the fetch request would also be marked as erroneous. This commit is reverted with commit 2aad2fea7d36 ("msgstore: revert 9fdc7acf5b48"). Send an erroneous message info message from the backend when an error is encountered for a specific UID. Fixes: 01f80721e283 ("msgstore: post MessageInfo on erroneous fetch") Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* Revert "worker: prevent deadlock by flooding worker.Messages channel"Moritz Poldrack2022-09-201-4/+1
| | | | | | | | | | This reverts commit 74735711595c3f0dc29177f767b2c91beef19617. The commit has introduced a regression that lead to the pager not being filled with content, thereby making reading mails impossible. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* worker: prevent deadlock by flooding worker.Messages channelTim Culverhouse2022-09-201-1/+4
| | | | | | | | | | | Send to worker.Messages in goroutine to prevent deadlocks: the UI can fill the worker.Actions channel. The worker can generate more than one Message per action, and if it generates enough to fill the worker.Messages channel from a single message while the worker.Actions channel is full, a deadlock occurs. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: prevent deadlock from posting actions to selfTim Culverhouse2022-09-201-0/+4
| | | | | | | | | | | | | | | | The IMAP worker has a few methods that post a new Action to itself. This can create a deadlock when the worker.Actions channel is full: The worker can't accept a new Action because it's trying to post an action. This is most noticeable when cached headers are enabled and the message list is scrolled fast. Use a goroutine to post actions to the worker when posting from within the worker. Fixes: https://todo.sr.ht/~rjarry/aerc/45 Fixes: 7aa71d334b27 ("imap: add option to cache headers") Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* lint: apply new formatting rulesMoritz Poldrack2022-08-011-3/+2
| | | | | | | Run `make fmt`. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* logging: use level-based logger functionsRobin Jarry2022-07-231-16/+12
| | | | | | | | | | | | Do not pass logger objects around anymore. Shuffle some messages to make them consistent with the new logging API. Avoid using %v when a more specific verb exists for the argument types. The loggers are completely disabled (i.e. Sprintf is not even called) by default. They are only enabled when redirecting stdout to a file. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* Remove worker callbacks when Done is receivedDrew DeVault2019-06-021-4/+12
|
* worker/types/worker: remove mutexSimon Ser2019-05-191-36/+21
| | | | | | | | | | Worker.callbacks contains two types of callbacks: some are action callbacks, some are message callbacks. Each of those is access from one side of the communication channel (UI goroutine vs. worker goroutine). Instead of using a channel, we can use two different maps for each kind. This simplifies the code and also ensures we don't call an action callback instead of a message callback (or the other way around).
* worker/types/worker: make ID allocation atomicSimon Ser2019-05-191-5/+6
| | | | | | | | Message IDs are allocated for both messages from UI to workers and the other way around. Hence, the global nextId variable is accessed from multiple goroutines. Instead, use atomic to access the global counter.
* worker/types/worker: set ID before sending messageSimon Ser2019-05-191-3/+9
| | | | | The previous code set the message ID after sending it, which could result in the receiver reading the ID before it's set.
* Copy sent emails to the Sent folderDrew DeVault2019-05-151-4/+12
| | | | Or rather, to a user-specified folder
* worker/types: fix Worker.Callbacks race conditionSimon Ser2019-04-271-15/+41
| | | | | | | | | | | | | Worker.Process* functions were called in different goroutines than Worker.Post*. Protect the map with a mutex. Also make the map unexported to prevent external unprotected accesses. Worker.Process* functions used to delete items from the map. However they didn't delete the element they retrieved: callbacks[msg.InResponseTo()] was read while callbacks[msg] was deleted. I'm not sure I understand why. I tried to delete the element that was accessed - but this broke everything (UI froze at "Connecting..."). I don't believe any elements were actually removed from the map, so the new code just doesn't remove anything.
* Improve loggingDrew DeVault2018-02-011-6/+20
|
* Reduce boilerplate in worker/UIDrew DeVault2018-02-011-0/+59