Skip to content

RTS option `--io-manager=native` gives error with `hDuplicateTo` and null device

EDIT: My second comment is a better description of the issue than my original post.

Summary

With a minimal test program, setting the GHCRTS environment variable to --io-manager=native results in an error, when other ways of setting that same RTS option (at compile time, on the command line) do not. It is the differing behaviour that makes me think this is a bug at the GHC level. EDIT: I was not thinking clearly: there is no inconsistency. This may not be a GHC issue. I will investigate further, and close this if I was mistaken. EDIT: I do think this is a GHC issue, see further below.

Steps to reproduce

Create a minimal Haskell program with Stack (say named ioTest-exe, using stack new ioTest) with Main.hs:

module Main (main) where

import GHC.IO.SubSystem (isWindowsNativeIO)

main :: IO ()
main = print isWindowsNativeIO

and package.yaml (extracts):

executables:
  ioTest-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N

and snapshot nightly-2022-09-05 (GHC 9.2.4).

[1] If the RTS option --io-manager=native is set in the package.yaml file as a GHC option, all is well:

executables:
  ioTest-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=--io-manager=native
    - -with-rtsopts=-N

[2] If the RTS option is not set in the package.yaml file, but is set at the command line when the compiled ioTest-exe is run, all is well:

stack exec -- ioTest-exe +RTS --io-manager=native -RTS

[3] However, if the option is not set as a GHC option or at the command line, but the GHCRTS environment variable is set:

> $Env:GHCRTS="--io-manager=native"
> dir Env:GHCRTS

Name                           Value
----                           -----
GHCRTS                         --io-manager=native

Then stack build fails. It fails with the following, but I think that may be the symptom, not the cause:

Encountered error while migrating Pantry database:
    \\.\NUL: hDuplicateTo: illegal operation (handles are incompatible)
Please report this on https://github.com/commercialhaskell/stack/issues
As a workaround you may delete Pantry database in C:\sr\pantry\pantry.sqlite3 triggering its recreation.

(With $Env:GHCRTS="--io-manager=posix", all is well.)

This was reported by a Stack user at: https://github.com/commercialhaskell/stack/issues/5851

Expected behavior

That setting GHCRTS should have the same effect as setting the same RTS option at the command line. EDIT: That setting GHCRTS should not cause Pantry/Stack to fail. This may be a problem with Pantry or one of its dependencies.

Environment

  • GHC version used: GHC 9.2.4 for the test program (the Stack executable itself is built with GHC 9.4.2).

Optional:

  • Operating System: Windows 11
  • System Architecture: x86_64
Edited by Mike Pilgrem
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information