Menu

Starting external process on Windows

Anonymous
2010-07-07
2013-04-30
  • Anonymous

    Anonymous - 2010-07-07

    Hello,
    im4java has a serious bug when starting an external process on Windows.

    The method ProcessStarter.waitForProcess first consumes the standard output, and after the stdout is fully consumed, starts processing stderr. This, however, can lead to a deadlock on Windows, where stdout and stderr share a common 4kb buffer. When this buffer gets filled by stderr messages, the processOutput method deadlocks, because it waits for the stderr messages being processed.

    This potential issue is documented at the very beginning o Javadoc for the java.lang.Process class:
    http://java.sun.com/javase/6/docs/api/java/lang/Process.html

    There are two possible solutions:

    1. Start a separate consumer threads for both stderr and stdout processing.
    2. or use the Apache Commons Exec library (http://commons.apache.org/exec/) that has all the process launching stuff implemented and tested.

    Is it an option to add a dependency on common-exec to im4java, or should we implement the output processing thread code ourselves?

    I need this issue to be fixed for my application and I'm willing to contribute a patch. Option no. 2 is naturally preferred.

    Jarda Snajdr

     
  • Bernhard Bablok

    Bernhard Bablok - 2010-07-08

    Hello Jarda,

    thanks for pointing this out. I already felt uncomfortable with the current solution but hesitated to change it because it somehow changes the semantic of the library. But a bug is bug and it should therefore be fixed.

    I will have a look at the issue and think about the proposed options. Both have there merits. On the one hand I don't like dependencies (especially on Apache libs - they are used everywhere and I experiences too many incompatibilities), on the other hand reimplementing already available code is also questionable.

    Could you provide me with a "working" example of the deadlock you describe? ImageMagick usually does not produce 4kB of stderr-output (unless you use the -debug option which is very questionable from java anyhow).

    Thanks, Bernhard

     

Log in to post a comment.