Jira (FACT-2682) facter -p returns NUL character on stdout when called from nested ruby on windows

1 view
Skip to first unread message

David Schmitt (Jira)

unread,
Jun 24, 2020, 3:16:04 PM6/24/20
to puppe...@googlegroups.com
David Schmitt created an issue
 
Facter / Bug FACT-2682
facter -p returns NUL character on stdout when called from nested ruby on windows
Issue Type: Bug Bug
Assignee: Unassigned
Components: Windows
Created: 2020/06/24 12:15 PM
Environment:

Personally reproduced with puppet 6.16.0, facter 3.14.11 (commit ed6c9052b125bee55f21f43d55f790c08ec75c1c), windows server 2019 (gusztavvargadr/windows-server) as well as the hydra demo environment.

See the linked tickets for more tangential reproduction environments going back to 2019.2.1.

Priority: Normal Normal
Reporter: David Schmitt

As result of the investigation into MODULES-10602 and FM-8887, it was found that facter misbehaves on windows when being called from another ruby process while at the same time also executing other processes:

When deploying the following fact to C:\ProgramData\PuppetLabs\puppet\cache\lib\facter\debugg.rb

Facter.add(:debugg) do
  setcode do
    puts `cmd /c echo bar`.inspect
  end
end

weird things start to happen:

PS C:\> & 'C:\Program Files\Puppet Labs\Puppet\puppet\bin\irb.bat'
irb(main):001:0>  `facter -p debugg`
=> "\x00\"bar\\n\"\n"
irb(main):002:0>

Note the \x00 at the start of the output. Replacing the backtick-call to cmd in the fact with a regular string makes the behaviour go away:

Facter.add(:debugg) do
  setcode do
    puts "bar\n".inspect
  end
end

irb(main):002:0> `facter -p debugg`
=> "\n\"bar\\n\"\n"
irb(main):003:0>

Curiously, using Puppet::Util::Execution.execute for calling facter also does not show the issue:

irb(main):004:0> Puppet::Util::Execution.execute("facter -p debugg")
=> "\n\"bar\\n\"\n"
irb(main):005:0>

I could verify that this is the cause for the behaviour seen in MODULES-10602 and FM-8887, and I could reproduce it with only the latest puppet-agent (6.16.0) installed on a windows server 2019 virtual box (gusztavvargadr/windows-server). Customers and SEs have reported seeing the same symptoms as far back as 2019.2.1.

For a full-featured repro environment, the hydra demo environments work out of the box, as (amongst others) the chocolateyversion fact triggers the bug.

I could not reproduce it on a litmusimage/centos:8 docker image with the same agent version:

david@zion:~/git/puppetlabs-motd (master)$ docker exec -ti litmusimage_centos_8-2225 /bin/bash
[root@40541a36d2a8 /]# cat /opt/puppetlabs/puppet/cache/lib/facter/debugg.rb
Facter.add(:debugg) do
  setcode do
    #puts `cmd /c echo bar`.inspect
    puts `echo bar`.inspect
  end
end
[root@40541a36d2a8 /]# /opt/puppetlabs/puppet/bin/irb 
irb(main):001:0> `facter -p debugg`
=> "\n\"bar\\n\"\n"
irb(main):002:0> exit
[root@40541a36d2a8 /]# puppet --version
6.16.0
[root@40541a36d2a8 /]# 

https://github.com/puppetlabs/puppetlabs-facter_task/pull/125 has a workaround for the facter_task task. Since it is neither a straight up functional equivalent, nor keeps other tasks from breaking, I'm hesitant to commit that PR as a "fix" for this issue.

See https://puppet.slack.com/archives/CF418R4BE/p1592905228073600 for extensive just-in-time debugging log.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Mihai Buzgau (Jira)

unread,
Jun 25, 2020, 1:38:03 AM6/25/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Jun 25, 2020, 1:38:03 AM6/25/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Jun 25, 2020, 2:27:02 AM6/25/20
to puppe...@googlegroups.com
Mihai Buzgau commented on Bug FACT-2682
 
Re: facter -p returns NUL character on stdout when called from nested ruby on windows

Was able to reproduce this on Puppet 6.16.0, both using `facter -p` and also by setting the FACTERLIB environment variable:

C:\Users\Administrator>"c:\Program Files\Puppet Labs\Puppet\puppet\bin\irb.bat"
irb(main):001:0> ENV['FACTERLIB']='C:\Program Files\Puppet Labs\Puppet\puppet\lib\ruby\facter'
=> "C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\lib\\ruby\\facter"
irb(main):002:0> `facter myf`
=> "\x00\"bar\\n\"\n"

Mihai Buzgau (Jira)

unread,
Jun 25, 2020, 3:39:04 AM6/25/20
to puppe...@googlegroups.com
Mihai Buzgau commented on Bug FACT-2682

At first, I thought that the addition of the functionality to detect built-in commands (https://tickets.puppetlabs.com/browse/FACT-2054) in Facter 3.14.7 was causing this issue. However, it seems that this is reproducible on Puppet 6.11.1, which has Facter 3.14.6:

C:\Users\Administrator>"c:\Program Files\Puppet Labs\Puppet\puppet\bin\irb.bat"
irb(main):001:0> `puppet --version`
=> "6.11.1\n"
irb(main):002:0> `facter --version`
=> "3.14.6 (commit 47c91659d7220d0b5c536f7e5fb1a541c1f0d36c)\n"
irb(main):003:0> `facter -p myf`
=> "\x00\"bar\\n\"\n" 

Mihai Buzgau (Jira)

unread,
Jun 25, 2020, 3:59:04 AM6/25/20
to puppe...@googlegroups.com
Mihai Buzgau commented on Bug FACT-2682

Puppet 6.9.0 behaves the same:

C:\Users\Administrator>"c:\Program Files\Puppet Labs\Puppet\puppet\bin\irb.bat"
irb(main):001:0> `puppet --version
irb(main):002:0` `
=> "6.9.0\n"
irb(main):003:0> `facter --version`
=> "3.14.4 (commit f076bf1e76ba6331273ef85787506e89ab0497c3)\n"
irb(main):004:0> `facter -p myf`
=> "\x00\"bar\\n\"\n" 

Mihai Buzgau (Jira)

unread,
Jun 25, 2020, 4:03:03 AM6/25/20
to puppe...@googlegroups.com
Mihai Buzgau commented on Bug FACT-2682

Puppet  6.0.0, Facter 3.12.0, same issue:

C:\Users\Administrator>"c:\Program Files\Puppet Labs\Puppet\puppet\bin\irb.bat"
irb(main):001:0> `puppet --version`
=> "6.0.0\n"
irb(main):002:0> `facter --version`
=> "3.12.0 (commit b76618ccecd07a146733e4984f0906f52846a773)\n"
irb(main):003:0> `facter -p myf`
=> "\x00\"bar\\n\"\n" 

Seems like this has been around since the release of Puppet 6

Josh Cooper (Jira)

unread,
Jun 25, 2020, 11:36:03 AM6/25/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Jun 26, 2020, 3:42:03 AM6/26/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Jun 26, 2020, 3:42:04 AM6/26/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Jun 30, 2020, 3:23:03 AM6/30/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Jul 2, 2020, 5:55:03 AM7/2/20
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Jul 9, 2020, 3:46:03 AM7/9/20
to puppe...@googlegroups.com

Claire Cadman (Jira)

unread,
Jul 13, 2020, 6:11:03 AM7/13/20
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages