readline icon indicating copy to clipboard operation
readline copied to clipboard

Fix a race condition in Refresh and wrapWriter

Open special opened this issue 8 years ago • 1 comments

These functions would bypass calling RuneBuffer.Refresh when Terminal.IsReading(), but this leads to a race condition when another goroutine is just beginning to read. The result is that the prompt is not erased or rewritten in some cases.

RuneBuffer.Refresh protects this with a mutex, and looks safe to call even when !IsReading(), so removing these redundant checks seems sufficient.

The tested scenario is to have goroutine A calling Readline in a loop and handling commands, and goroutine B periodically printing to Instance.Stdout(). If the print in B is timed just before A calls Readline, the printed line is displayed after the prompt and the prompt is not reprinted until the next input.

special avatar Oct 23 '16 16:10 special

Thanks @special - I can confirm this fixes an issue for me with Gopherbot running in Gitpod.

parsley42 avatar Feb 13 '20 18:02 parsley42