Impossible to abort slow read and write

23 views
Skip to first unread message

Brennan Vincent

unread,
Oct 27, 2020, 10:22:45 PM10/27/20
to vim...@vim.org
Let's simulate a read that will block forever:

$ mkfifo /tmp/myfifo
$ vim /tmp/myfifo

Now vim hangs permanently; it cannot be killed or suspended except by
going to another terminal and running `pkill -9 vim`. (Or, of course,
writing stuff to the fifo, but the point here wasn't about fifos
specifically, but just about reads that are slow to return for whatever
reason).

Same story with :w or :w! to a file that is slow to write.

IMO, this "hang forever and give the user no way to recover" behavior is
a bug, but reasonable people might disagree.

Bram Moolenaar

unread,
Oct 28, 2020, 6:32:54 AM10/28/20
to vim...@googlegroups.com, Brennan Vincent, vim...@vim.org
It's not so easy to make this work, especially with a fifo. Vim is in
raw mode, thus a CTRL-C is not turned into an interrupt. We could
switch to cooked mode for that, but then any typeahead is becoming a
problem.

The hang actually already happens on open(), thus using select() or some
other mechanism to check if the file handle is readable doesn't help
much. Not sure if there is any other way.

BTW: Vim can be killed with a TERM signal in this situation, at least on
Linux.

--
hundred-and-one symptoms of being an internet addict:
138. You develop a liking for cold coffee.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Marius Gedminas

unread,
Oct 28, 2020, 12:45:40 PM10/28/20
to Bram Moolenaar, vim...@googlegroups.com, Brennan Vincent, vim...@vim.org
On Wed, Oct 28, 2020 at 11:32:42AM +0100, Bram Moolenaar wrote:
> Brennan Vincent wrote:
>
> > Let's simulate a read that will block forever:
> >
> > $ mkfifo /tmp/myfifo
> > $ vim /tmp/myfifo
> >
> > Now vim hangs permanently; it cannot be killed or suspended except by
> > going to another terminal and running `pkill -9 vim`. (Or, of course,
> > writing stuff to the fifo, but the point here wasn't about fifos
> > specifically, but just about reads that are slow to return for whatever
> > reason).
> >
> > Same story with :w or :w! to a file that is slow to write.
> >
> > IMO, this "hang forever and give the user no way to recover" behavior is
> > a bug, but reasonable people might disagree.
>
> It's not so easy to make this work, especially with a fifo. Vim is in
> raw mode, thus a CTRL-C is not turned into an interrupt. We could
> switch to cooked mode for that, but then any typeahead is becoming a
> problem.

Would switching to cbreak mode help? It works like raw, but converts ^C
to an interrupt.

(I'm not sure exactly when, but it seems to me that in the last year or
so modern versions of Vim became harder to interrupt with ^C, especially
when a plugin is running.)

Marius Gedminas
--
Apologies for taking up the bandwidth with the apology. Anything else I
can apologise for ...... er no can't think of anything, sorry about that.
Andy Hunt (Member of British Olympic Apology Squad)
signature.asc

Bram Moolenaar

unread,
Oct 29, 2020, 2:35:00 PM10/29/20
to vim...@googlegroups.com, Marius Gedminas, Brennan Vincent, vim...@vim.org

Marius Gedminas wrote:

> On Wed, Oct 28, 2020 at 11:32:42AM +0100, Bram Moolenaar wrote:
> > Brennan Vincent wrote:
> >
> > > Let's simulate a read that will block forever:
> > >
> > > $ mkfifo /tmp/myfifo
> > > $ vim /tmp/myfifo
> > >
> > > Now vim hangs permanently; it cannot be killed or suspended except by
> > > going to another terminal and running `pkill -9 vim`. (Or, of course,
> > > writing stuff to the fifo, but the point here wasn't about fifos
> > > specifically, but just about reads that are slow to return for whatever
> > > reason).
> > >
> > > Same story with :w or :w! to a file that is slow to write.
> > >
> > > IMO, this "hang forever and give the user no way to recover" behavior is
> > > a bug, but reasonable people might disagree.
> >
> > It's not so easy to make this work, especially with a fifo. Vim is in
> > raw mode, thus a CTRL-C is not turned into an interrupt. We could
> > switch to cooked mode for that, but then any typeahead is becoming a
> > problem.
>
> Would switching to cbreak mode help? It works like raw, but converts ^C
> to an interrupt.

It's worth a try: basically use RAW mode, with the exception that the
"ISIG" flag is set. This can be implemented in mch_settmode() with a
new argument TMODE_RAW. Would have to do this for all implementations
of mch_settmode().

> (I'm not sure exactly when, but it seems to me that in the last year or
> so modern versions of Vim became harder to interrupt with ^C, especially
> when a plugin is running.)

Well, if a plugin keeps the CPU busy, it may not checked for typed
characters.

--
hundred-and-one symptoms of being an internet addict:
149. You find your computer sexier than your girlfriend
Reply all
Reply to author
Forward
0 new messages