Debian Codegraph @

TODO

raw
1 * System.Console.Regions handling of outputConcurrent and errorConcurrent
2 when the output lacks a newline is surprising. The output may never be
3 displayed. A better approach:
4
5 When output arrives that lacks a newline, allocate a region for it
6 and buffer it in that region, so it displays immediately and more
7 output will go to the same region. When a newline arrives, close the
8 region and scroll up the completed line the same way any completed region
9 is displayed.
10
11 * Parts of System.Console.Concurrent may not be async exception safe.
12
13 If a thread is running an action from that module and an async exception
14 is sent to it, it may result in a deadlock or other problem.
15
16 (System.Console.Regions has been made safe,
17 also outputConcurrent and errorConcurrent.)
18
19 Particularly problematic is takeOutputLock', which takes the lock
20 and then outputs buffers to the console. If the emitOutputBuffer
21 calls are interrupted by async exception, it will be left locked
22 and the buffered output is also lost. But masking them is not good
23 because emitOutputBuffer could run for a long time in some situations.
24
25 fgProcess and bgProcess also do stuff with registerOutputThread/unregisterOutputThread
26 that may not be async exception safe.
27
28 And createProcessForeground uses takeOutputLock but then calls fgProcess,
29 which could be interrupted (during its call to registerOutputThread)
30 before it starts the async thread that drops the lock.
31
32 One approach to all this might be to fork off a worker thread,
33 which will thus be immune to any async exception directed at the calling
34 thread.
35
36 * Calling setConsoleRegion with something that throws an error
37 will cause no further display updates to happen.
38
39 The exception in the thunk will crash the displayThread,
40 and that is not waited on until the action passed to displayConsoleRegions
41 finishes, so the exception is deferred to that point. Of course if the
42 action never finishes, that hides the exception.
43
44 It does seem this should be improved, by catching the crashing
45 displayThread and ideally propigating the exception immediately.
46 But displayConsoleRegions would need to use a different class than
47 the current MonadIO to be able to do that. Eg, MonadBaseControl
48 so lifted-async can be used, or a class that lets the action be
49 canceled.
50
51 Or it could be dealt with by having setConsoleRegion force the thunk
52 before passing it over to the displayThread. But the instance
53 ToRegionContent (STM Text) seems to prevent doing that.