{"action":"created","comment":{"url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/comments/79081372","id":79081372,"diff_hunk":"@@ -200,58 +229,115 @@ def self.wait_on(wait_object, timeout_ms = 50)\n         wait_result\n       end\n \n-      def write_stdin(input)\n-        @stdin.puts(input)\n-      rescue => e\n-        msg = \"Error writing STDIN / reading STDOUT: #{e}\"\n-        raise Puppet::Util::Windows::Error.new(msg)\n+      # 1 byte command identifier\n+      #     0 - Exit\n+      #     1 - Execute\n+      def pipe_command(command)\n+        case command\n+        when :exit\n+          \"\\x00\"\n+        when :execute\n+          \"\\x01\"\n+        end\n+      end\n+\n+      def pipe_data(data)\n+        msg = data.encode(Encoding::UTF_8)\n+        [msg.bytes.length].pack('V') + msg.force_encoding(Encoding::BINARY)\n+        # raw_message = data.encode(Encoding::UTF_8).bytes.to_a\n+        # # iterate with each, appending to front of buffer in reverse order, which is what .NET expects\n+        # [raw_message.length].pack('N').bytes.reverse.each { |b| raw_message.insert(0, b) }\n+        # # raw_message.insert(0, 1)\n+\n+        # raw_message\n+        # msg = data.encode(Encoding::UTF_8) + \"\\n\"\n+\n+        # \"#{msg.length}\\n\" + msg\n+      end\n+\n+      def write_pipe(input)\n+        @pipe.syswrite(input)\n+        @pipe.flush()\n       end\n \n       def drain_pipe(pipe, iterations = 10)\n         output = []\n         0.upto(iterations) do\n           break if !self.class.is_readable?(pipe, 0.1)\n-          l = pipe.gets\n+          # require 'pry'; binding.pry\n+          l = pipe.readpartial(4096)\n           Puppet.debug \"#{Time.now} PIPE> #{l}\"\n           output << l\n         end\n         output\n       end\n \n-      def read_stdout(output_ready_event, wait_interval_ms = 50)\n+      def read_pipe(output_ready_event, wait_interval_ms = 50)\n         output = []\n         errors = []\n         waited = 0\n \n         # drain the pipe while waiting for the event signal\n+        # but prevent an infinite loop by validating the process, pipes, etc\n         while WAIT_TIMEOUT == self.class.wait_on(output_ready_event, wait_interval_ms)\n+          # Ruby will gleefully allow trying to read stdout / stderr that are\n+          # no longer connected to a live process, so therefore check the\n+          # liveness here and raise the broken pipe error that Ruby would usually\n+          raise Errno::EPIPE if !alive?\n           # TODO: While this does ensure that both pipes have been\n           # drained it can block on either longer than necessary or\n           # deadlock waiting for one or the other to finish. The correct\n           # way to deal with this is to drain each pipe from seperate threads\n           # but time ran on in this implementation and this will be addressed soon\n-          output << drain_pipe(@stdout)\n+          output << drain_pipe(@pipe)\n           errors << drain_pipe(@stderr)\n           waited += wait_interval_ms\n         end\n \n         Puppet.debug \"Waited #{waited} total milliseconds.\"\n \n         # once signaled, ensure everything has been drained\n-        output << drain_pipe(@stdout, 1000)\n+        output << drain_pipe(@pipe, 1000)\n         errors << drain_pipe(@stderr, 1000)\n \n         errors = errors.reject { |e| e.empty? }\n+                  .map { |arr| arr.map { |e| e.force_encoding(Encoding::UTF_8) }}\n \n-        return output.join(''), errors\n-      rescue => e\n-        msg = \"Error reading PIPE: #{e}\"\n-        raise Puppet::Util::Windows::Error.new(msg)\n+        return output.join('').force_encoding(Encoding::UTF_8), errors\n       end\n \n       def exec_read_result(powershell_code, output_ready_event)\n-        write_stdin(powershell_code)\n-        read_stdout(output_ready_event)\n+        write_pipe(pipe_command(:execute))\n+        write_pipe(pipe_data(powershell_code))\n+        read_pipe(output_ready_event)\n+      rescue EOFError => eoferror # a specific type of IOError\n+        Puppet.warning [eoferror.inspect, eoferror.backtrace].join(\"\\n\")\n+        # require 'pry'; binding.pry\n+        # pipes are closed (could be as a result of tearing down process)\n+        @usable = false\n+        return nil, [eoferror.inspect]","path":"lib/puppet_x/puppetlabs/powershell/powershell_manager.rb","position":240,"original_position":240,"commit_id":"904eee9e5adb36d71fe7af2c720d2cd1ec0cbdf4","original_commit_id":"904eee9e5adb36d71fe7af2c720d2cd1ec0cbdf4","user":{"login":"glennsarti","id":5819622,"avatar_url":"https://avatars.githubusercontent.com/u/5819622?v=3","gravatar_id":"","url":"https://api.github.com/users/glennsarti","html_url":"https://github.com/glennsarti","followers_url":"https://api.github.com/users/glennsarti/followers","following_url":"https://api.github.com/users/glennsarti/following{/other_user}","gists_url":"https://api.github.com/users/glennsarti/gists{/gist_id}","starred_url":"https://api.github.com/users/glennsarti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glennsarti/subscriptions","organizations_url":"https://api.github.com/users/glennsarti/orgs","repos_url":"https://api.github.com/users/glennsarti/repos","events_url":"https://api.github.com/users/glennsarti/events{/privacy}","received_events_url":"https://api.github.com/users/glennsarti/received_events","type":"User","site_admin":false},"body":"This seems to be causing an issue later on.  This returns a single element array of type string however the code in https://github.com/puppetlabs/puppetlabs-powershell/blob/master/lib/puppet/provider/exec/powershell.rb#L83-L87 is expecting an array of an array of strings.  This is causing an error e.g.\r\n```\r\n#<NoMethodError: undefined method `each' for \"#<EOFError: end of file reached>\":String>\r\n```\r\n\r\nMay have to change this ` return nil, [[eoferror.inspect]]` and the ones below as well","created_at":"2016-09-15T23:11:46Z","updated_at":"2016-09-15T23:11:57Z","html_url":"https://github.com/puppetlabs/puppetlabs-powershell/pull/142#discussion_r79081372","pull_request_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142","_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/comments/79081372"},"html":{"href":"https://github.com/puppetlabs/puppetlabs-powershell/pull/142#discussion_r79081372"},"pull_request":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142"}}},"pull_request":{"url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142","id":84346749,"html_url":"https://github.com/puppetlabs/puppetlabs-powershell/pull/142","diff_url":"https://github.com/puppetlabs/puppetlabs-powershell/pull/142.diff","patch_url":"https://github.com/puppetlabs/puppetlabs-powershell/pull/142.patch","issue_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues/142","number":142,"state":"open","locked":false,"title":"(MODULES-3690) WIP","user":{"login":"Iristyle","id":394081,"avatar_url":"https://avatars.githubusercontent.com/u/394081?v=3","gravatar_id":"","url":"https://api.github.com/users/Iristyle","html_url":"https://github.com/Iristyle","followers_url":"https://api.github.com/users/Iristyle/followers","following_url":"https://api.github.com/users/Iristyle/following{/other_user}","gists_url":"https://api.github.com/users/Iristyle/gists{/gist_id}","starred_url":"https://api.github.com/users/Iristyle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Iristyle/subscriptions","organizations_url":"https://api.github.com/users/Iristyle/orgs","repos_url":"https://api.github.com/users/Iristyle/repos","events_url":"https://api.github.com/users/Iristyle/events{/privacy}","received_events_url":"https://api.github.com/users/Iristyle/received_events","type":"User","site_admin":false},"body":"Use custom named pipe instead of stdin","created_at":"2016-09-07T18:04:07Z","updated_at":"2016-09-15T23:11:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2af5e8dfd53c4ebe8ab962ded77f9db53e374c16","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142/commits","review_comments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142/comments","review_comment_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues/142/comments","statuses_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/statuses/904eee9e5adb36d71fe7af2c720d2cd1ec0cbdf4","head":{"label":"Iristyle:ticket/stable/MODULES-3690-WMF5.1-hangs-powershell_manager-custom-IPC","ref":"ticket/stable/MODULES-3690-WMF5.1-hangs-powershell_manager-custom-IPC","sha":"904eee9e5adb36d71fe7af2c720d2cd1ec0cbdf4","user":{"login":"Iristyle","id":394081,"avatar_url":"https://avatars.githubusercontent.com/u/394081?v=3","gravatar_id":"","url":"https://api.github.com/users/Iristyle","html_url":"https://github.com/Iristyle","followers_url":"https://api.github.com/users/Iristyle/followers","following_url":"https://api.github.com/users/Iristyle/following{/other_user}","gists_url":"https://api.github.com/users/Iristyle/gists{/gist_id}","starred_url":"https://api.github.com/users/Iristyle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Iristyle/subscriptions","organizations_url":"https://api.github.com/users/Iristyle/orgs","repos_url":"https://api.github.com/users/Iristyle/repos","events_url":"https://api.github.com/users/Iristyle/events{/privacy}","received_events_url":"https://api.github.com/users/Iristyle/received_events","type":"User","site_admin":false},"repo":{"id":36790021,"name":"puppetlabs-powershell","full_name":"Iristyle/puppetlabs-powershell","owner":{"login":"Iristyle","id":394081,"avatar_url":"https://avatars.githubusercontent.com/u/394081?v=3","gravatar_id":"","url":"https://api.github.com/users/Iristyle","html_url":"https://github.com/Iristyle","followers_url":"https://api.github.com/users/Iristyle/followers","following_url":"https://api.github.com/users/Iristyle/following{/other_user}","gists_url":"https://api.github.com/users/Iristyle/gists{/gist_id}","starred_url":"https://api.github.com/users/Iristyle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Iristyle/subscriptions","organizations_url":"https://api.github.com/users/Iristyle/orgs","repos_url":"https://api.github.com/users/Iristyle/repos","events_url":"https://api.github.com/users/Iristyle/events{/privacy}","received_events_url":"https://api.github.com/users/Iristyle/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Iristyle/puppetlabs-powershell","description":"powershell provider for the Puppet exec resource type","fork":true,"url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell","forks_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/forks","keys_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/teams","hooks_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/hooks","issue_events_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/issues/events{/number}","events_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/events","assignees_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/assignees{/user}","branches_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/branches{/branch}","tags_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/tags","blobs_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/git/refs{/sha}","trees_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/statuses/{sha}","languages_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/languages","stargazers_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/stargazers","contributors_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/contributors","subscribers_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/subscribers","subscription_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/subscription","commits_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/commits{/sha}","git_commits_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/git/commits{/sha}","comments_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/comments{/number}","issue_comment_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/issues/comments{/number}","contents_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/contents/{+path}","compare_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/merges","archive_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/downloads","issues_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/issues{/number}","pulls_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/pulls{/number}","milestones_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/milestones{/number}","notifications_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/labels{/name}","releases_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/releases{/id}","deployments_url":"https://api.github.com/repos/Iristyle/puppetlabs-powershell/deployments","created_at":"2015-06-03T08:23:18Z","updated_at":"2016-05-05T23:48:17Z","pushed_at":"2016-09-15T20:11:25Z","git_url":"git://github.com/Iristyle/puppetlabs-powershell.git","ssh_url":"git@github.com:Iristyle/puppetlabs-powershell.git","clone_url":"https://github.com/Iristyle/puppetlabs-powershell.git","svn_url":"https://github.com/Iristyle/puppetlabs-powershell","homepage":"forge.puppetlabs.com/puppetlabs/powershell","size":22191,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"puppetlabs:stable","ref":"stable","sha":"56503f27db7f9762ef0643da7a94252e5201bf0e","user":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":7831726,"name":"puppetlabs-powershell","full_name":"puppetlabs/puppetlabs-powershell","owner":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/puppetlabs/puppetlabs-powershell","description":"powershell provider for the Puppet exec resource type","fork":false,"url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell","forks_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/forks","keys_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/teams","hooks_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/hooks","issue_events_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues/events{/number}","events_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/events","assignees_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/assignees{/user}","branches_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/branches{/branch}","tags_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/tags","blobs_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/git/refs{/sha}","trees_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/statuses/{sha}","languages_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/languages","stargazers_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/stargazers","contributors_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/contributors","subscribers_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/subscribers","subscription_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/subscription","commits_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/commits{/sha}","git_commits_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/git/commits{/sha}","comments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/comments{/number}","issue_comment_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues/comments{/number}","contents_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/contents/{+path}","compare_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/merges","archive_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/downloads","issues_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues{/number}","pulls_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls{/number}","milestones_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/milestones{/number}","notifications_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/labels{/name}","releases_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/releases{/id}","deployments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/deployments","created_at":"2013-01-26T01:16:29Z","updated_at":"2016-09-05T22:24:53Z","pushed_at":"2016-09-15T20:11:25Z","git_url":"git://github.com/puppetlabs/puppetlabs-powershell.git","ssh_url":"git@github.com:puppetlabs/puppetlabs-powershell.git","clone_url":"https://github.com/puppetlabs/puppetlabs-powershell.git","svn_url":"https://github.com/puppetlabs/puppetlabs-powershell","homepage":"forge.puppetlabs.com/puppetlabs/powershell","size":22388,"stargazers_count":32,"watchers_count":32,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":6,"forks":45,"open_issues":6,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142"},"html":{"href":"https://github.com/puppetlabs/puppetlabs-powershell/pull/142"},"issue":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues/142"},"comments":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/issues/142/comments"},"review_comments":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142/comments"},"review_comment":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/pulls/142/commits"},"statuses":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-powershell/statuses/904eee9e5adb36d71fe7af2c720d2cd1ec0cbdf4"}}}}
{"actor":{"display_login":"glennsarti"}}