A job's bufferevent has EV_WRITE enabled by default, but libevent
internals prevent the job_write_callback from being invoked unless
we do (at least one of):

  - call bufferevent_enable with EV_WRITE, or
  - call bufferevent_write with non-zero length data

Either of these will enable the internal event that handles writing,
which will eventually invoke the job_write_callback.

Jobs from copy-pipe will eventually write some data, but those from
run-shell and if-shell do not write data, so job_write_callback is
never called. Thus, for run-shell and if-shell jobs, the writing
half of the socket is never shutdown, and job processes that try to
read from their stdin will hang indefinitely.

To prevent this "hanging stdin" for run-shell and if-shell jobs
(which can also hang the client's cmdq if -b is not used),
explicitly enable EV_WRITE for all jobs.

---

Sorry for not catching this earlier. I tested copy-pipe jobs that
write to stdout/stderr, but I failed to test run-shell jobs that
read from stdin.

Nicholas even mentioned the lack of EV_WRITE in the initial patch.
When I investigated the libevent code, I found that EV_WRITE is
"enabled" by default, but I did not notice that the internal event
is never actually event_add()ed unless we poke the bufferevent in
the right way.
---
 job.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/job.c b/job.c
index 6a7286a..33cdc76 100644
--- a/job.c
+++ b/job.c
@@ -108,7 +108,7 @@ job_run(const char *cmd, struct session *s,
 
        job->event = bufferevent_new(job->fd, NULL, job_write_callback,
            job_callback, job);
-       bufferevent_enable(job->event, EV_READ);
+       bufferevent_enable(job->event, EV_READ|EV_WRITE);
 
        log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid);
        return (job);
-- 
1.8.2


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to