Tags: bokwoon95/wgo
Tags
Fix -stdin being blocked after a restart until Enter is pressed. Closes #22. os.Stdin.Read() blocks until a newline `\n` is provided (due to the OS doing line-by-line buffering https://groups.google.com/g/golang-nuts/c/NvD-pOTASIk). Therefore, do not tie the lifecycle of a command with os.Stdin.Read(). Instead, read from os.Stdin continuously in a background goroutine and feed its data into the stdinPipe of whichever exec.Cmd is currently running.
fix bug where we were unwatching everything but 256 files, instead of…
… just unwatching 256 files
Unwatching occurs when we hit the syscall.EMFILE error ("too many open files"),
and we need to unwatch so that we have some file descriptors available for
starting commands i.e. cmd.Start(). On macOS, creating a timer for debouncing
already consumes a file descriptor [1], and if there are no file descriptors
available it panics with a very intimidating stack trace.
[1] https://dzone.com/articles/go-servers-understanding-epoll-kqueue-netpoll#:~:text=kqueue%20is%20a%20similar%20mechanism%2C%20where%20registered%20events%20(read/write%2C%20timers%2C%20signals%2C%20files)%20are%20handled%20via%20kevent
make unwatching when we hit "too many open files" deterministic Also clarify in the log message that it's the number of directories watched, not number of files watched. We don't actually know the number of files watched since we only add directories to the watcher. On kqueue (macOS) that translates to one file descriptor used per directory and one file decriptor used per file, while on inotify (Linux) only needs one file descriptor per directory (https://news.ycombinator.com/item?id=9063910).
properly drain the timer before use this might have been the source of various race conditions I saw in the past 😩 references: https://www.reddit.com/r/golang/comments/1inw7nc/anyone_else_seeing_old_unit_tests_that_involve/ https://blogtitle.github.io/go-advanced-concurrency-patterns-part-2-timers/#time-newtimer
PreviousNext