enkessler / childprocess

Cross-platform Ruby library for managing child processes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

posix_spawn and fork-exec do not treat non-string environment variables the same

shepmaster opened this issue · comments

I was setting the environment of a process to this:

{
      TEST_GITHUB_DISABLED: true,
      DATABASE_URL: "A string",
      API_HTTP_PORT: 8080,
}

This was working well, but then I set ChildProcess.posix_spawn = true as suggested by the README. I then started getting exceptions because val no longer implemented include?.

I don't have much of an opinion which way is correct, but it would be nice for them to be consistent.

It's not clear to me whether ChildProcess should convert values like true or numerical values to an equivalent string. Is true the string true? Or the string 1? Something else?

Given the potential ambiguity, it's best for applications to set environment variables as strings explicitly. Unfortunately, the existing implementation of this gem seems to convert values to string equivalents for the non-posix_spawn case.

Given that the common case is the fork/exec implementation, we'll go with that behavior, and have implemented it in 5c57733. However, long-term we should migrate to raising an error on non-string values.

Thanks for the report!