<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 15 October 2013 03:15, Dimitar Zhekov <span dir="ltr"><<a href="mailto:dimitar.zhekov@gmail.com" target="_blank">dimitar.zhekov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm looking how to fix this famous bug without too many changes, and<br>
found something strange: tools.c runs it's command with spawn async,<br>
but uses blocking I/O to read the data from stdout/stderr.<br></blockquote><div><br></div><div>Given that it sets up io channels and callbacks when data is available I suspect that the writer thought they were using asynchronous i/o. ;)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Any idea why is that? What comes to ming is blocking Geany until the<br>
command finishes, to be sure that the current document still exists and<br>
it's selection is unchanged, and thus can be safely replaced with the<br>
command output.<br></blockquote><div><br></div><div>This would be a correct reason to block Geany, but deliberately, not by accident.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
However, if we block reading stderr on Windows, and the command outputs<br>
4KB (or whatever is the limit) to stdout, that'll cause a deadlock, as<br>
evident by the previous messages in this thread. Same if reading stdout<br>
and the command produces a lot of stderr, though that's unlikely.<br></blockquote><div><br></div><div>Its likely to do the same on Linux, but IIUC the limit is larger these days, 64k = 16 * PIPE_BUF.  (The 16 is a #define in the kernal)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I can emulate the (non-)blocking behaviour, but am not sure if this<br>
flag currently has any effect under Windows, considering it's buggy<br>
implementation of g_io_add_watch and g_io_channel_set_flags for<br>
pipes (which are the problem to fix in the first place).<br>
<br></blockquote><div><br></div><div>Or possibly try the more complicated GIO g_input_stream_read_async() and friends and see if it works on windows.</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

If tools_execute_custom_command really wants to block Geany, the right<br>
thing is to spawn the command, and then cycle reading stderr and<br>
stdout asynchronously until the command completes, instead of adding<br>
I/O watches to the message loop just to block it.<br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
The current loop that writes the selection to stdin seems capable of<br>
causing a deadlock under Windows too, if the command generates 4KB<br>
output and stops before the full selection is written, since we use<br>
blocking I/O to write to stdin...<br></blockquote><div><br></div><div>And not just on windows, if the selection is a whole file it can easily exceed the Linux limit of 64k.</div><div><br></div><div>Basically the whole spawning thing needs to be looked at critically, especially those uses that do i/o to the child process.  A working version of each permutation sync/async, reads/writes/both needs to be put in utils and all of Geany should then use that implementation and the callbacks use known good idioms.</div>
<div><br></div><div>Cheers</div><div>Lex</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
--<br>
E-gards: Jimmy<br>
_______________________________________________<br>
Devel mailing list<br>
<a href="mailto:Devel@lists.geany.org">Devel@lists.geany.org</a><br>
<a href="https://lists.geany.org/cgi-bin/mailman/listinfo/devel" target="_blank">https://lists.geany.org/cgi-bin/mailman/listinfo/devel</a><br>
</div></div></blockquote></div><br></div></div>