dspinellis / dgsh

Shell supporting pipelines to and from multiple processes
http://www.spinellis.gr/sw/dgsh/
Other
323 stars 22 forks source link

Pipe ending in function containing pipes causes negotiation failure #88

Closed lucaswerkmeister closed 7 years ago

lucaswerkmeister commented 7 years ago

With the following content in the file script,

function g {
    /bin/cat | /bin/cat
}

/bin/cat /dev/null | g

dgsh script results in the following output:

ames@b<U/holocal/bcatcatcat14792 dgsh: timeout for negotiation. Exit.
14794 dgsh: timeout for negotiation. Exit.
14795 dgsh: timeout for negotiation. Exit.

The garbage at the beginning is printed immediately and looks a lot like random memory being dumped. The rest of the output is printed after the five second timeout.

In a similar script, which you can find in this gist, I’ve also encountered an assertion failure:

dgsh-wrap: negotiate.c:2339: read_input_fds: Assertion `this_nc->node_index == self_node.index' failed.
dgsh-conc: exiting before dgsh negotiation is complete
dgsh-tee: negotiate.c:2339: read_input_fds: Assertion `this_nc->node_index == self_node.index' failed.
[the code of the countDescriptions function is interleaved with the output from here on]
15436 Aborted
15437 Segmentation fault
15424 dgsh: timeout for negotiation. Exit.

In both cases, there’s a simple workaround: pipe to cat.

Might be related to or duplicate of #4.

dspinellis commented 7 years ago

IMO this is a bug: dgsh should not have attempted to negotiate.

On the other hand, ou're trying to mix water with oil: having dgsh (rather than bash) execute a script where you've forced commands to be non-dgsh compatible. I assume this is an example of a more complex scenario. What are you trying to achieve?

lucaswerkmeister commented 7 years ago

having dgsh (rather than bash) execute a script where you've forced commands to be non-dgsh compatible.

The same bug occurs with cat instead of /bin/cat (and the printed garbage in that case includes dgsh-tee, so presumably that time it’s using the dgsh version) – I just thought the version without dgsh-aware tools was the simpler one to reproduce the bug.

I assume this is an example of a more complex scenario. What are you trying to achieve?

The more complex scenario is the script (see also the comment on the gist for details) that I shared near the end of the bug (which includes a multipipe); even though the error that occurs is different, both scripts have a pipeline ending in a function, and in both cases the workaround is to append cat to the pipeline, so I suspect it’s the same bug.

dspinellis commented 7 years ago

You definitely need cat or a similar gathering command at the end of the multipipe, because summarizeDescriptions cannot accept four inputs, so the negotiation would fail.

lucaswerkmeister commented 7 years ago

There already is a cat after the multipipe, but this is the buggy version of the script. The workaround is another cat after summarizeDescriptions.

mfragkoulis commented 7 years ago

You are right, it should be the same bug. I have tracked it down and I am working on a solution. Hopefully, I will have it tomorrow.

mfragkoulis commented 7 years ago

Does it resolve the bug?

lucaswerkmeister commented 7 years ago

Seems to have fixed it, thanks!