clojure.java.process/start return implements IBlockingDeref incorrectly

Description

Per

clojure.java.process/start returns a reify of ILookup, IDeref, and IBlockingDeref.

The IBlockingDeref implementation is wrong - it just passes the two timeout args from blocking (deref [ref timeout-ms timeout-val]) to Process.waitFor(long timeout, TimeUnit unit). Those don’t match. Also, the return value of the 2-arity Process.waitFor() is a boolean, instead of the exit value returned from the 0-arity, so that is also broken.

Additionally:

  • Both impls of deref return boxed Integer, should return Long.

  • start should not return an object that is both a value (streams map) and a reference (for waiting). Simply return the Process, and provide a helper exit-ref that can wait for the process and return the exit code on completion.

 

Approach: Correctly implement the blocking deref arity to always use TimeUnit/MILLISECONDS as the timeout unit, return the timeout value on timeout, and return the exit value on non-timeout.

Change start return, add exit-ref, remove ok? (as it is then just a zero? check on exit-ref). Add stdout stderr and stdin helpers to pull the correct stream from the Process.

Patch: clj-2865-6.patch

Screened by: fogus

Environment

None

Attachments

6

Activity

Show:

Alex Miller July 29, 2024 at 7:03 PM

Released in 1.12.0-beta2

Michael Fogus July 16, 2024 at 5:15 PM

Reworked my screen scratch code to work with new functions in -4. LGTM

Michael Fogus July 9, 2024 at 2:21 PM

Checked that patch -2 works the same as patch -1 but additionally checked that boxed Integers are no longer returned.

Fixed

Details

Assignee

Reporter

Labels

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created June 28, 2024 at 1:47 PM
Updated July 29, 2024 at 7:03 PM
Resolved July 29, 2024 at 7:03 PM