{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/27152","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/27152/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/27152/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/27152/events","html_url":"https://github.com/rust-lang/rust/issues/27152","id":96092156,"number":27152,"title":"std::process::Command.status() hangs if subprocess output is >64K characters","user":{"login":"TheJakeSchmidt","id":10720216,"avatar_url":"https://avatars.githubusercontent.com/u/10720216?v=3","gravatar_id":"","url":"https://api.github.com/users/TheJakeSchmidt","html_url":"https://github.com/TheJakeSchmidt","followers_url":"https://api.github.com/users/TheJakeSchmidt/followers","following_url":"https://api.github.com/users/TheJakeSchmidt/following{/other_user}","gists_url":"https://api.github.com/users/TheJakeSchmidt/gists{/gist_id}","starred_url":"https://api.github.com/users/TheJakeSchmidt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheJakeSchmidt/subscriptions","organizations_url":"https://api.github.com/users/TheJakeSchmidt/orgs","repos_url":"https://api.github.com/users/TheJakeSchmidt/repos","events_url":"https://api.github.com/users/TheJakeSchmidt/events{/privacy}","received_events_url":"https://api.github.com/users/TheJakeSchmidt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-libs","name":"A-libs","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-20T15:44:54Z","updated_at":"2015-07-20T17:00:41Z","closed_at":"2015-07-20T16:19:53Z","body":"std::process::Command hangs in status(), even if output() was called first, if the subprocess prints more than 64K characters to stdout.\r\n\r\nThis Rust program hangs between the two println!() statements, but passes if you change 65536 to 65535:\r\n\r\n    use std::process::Command;\r\n    use std::process::Stdio;\r\n\r\n    fn main() {\r\n        let mut process = Command::new(\"python\");\r\n        process.arg(\"-c\").arg(\"print('a' * 65536)\")\r\n            .stdout(Stdio::piped())\r\n            .stdin(Stdio::null())\r\n            .stderr(Stdio::null())\r\n            .output();\r\n        println!(\"Calling status()\");\r\n        process.status();\r\n        println!(\"status() returned\");\r\n    }\r\n\r\nI tested this with rustc version \"rustc 1.3.0-dev (c70417bd1 2015-07-20)\"."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/122951581","html_url":"https://github.com/rust-lang/rust/issues/27152#issuecomment-122951581","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/27152","id":122951581,"user":{"login":"TheJakeSchmidt","id":10720216,"avatar_url":"https://avatars.githubusercontent.com/u/10720216?v=3","gravatar_id":"","url":"https://api.github.com/users/TheJakeSchmidt","html_url":"https://github.com/TheJakeSchmidt","followers_url":"https://api.github.com/users/TheJakeSchmidt/followers","following_url":"https://api.github.com/users/TheJakeSchmidt/following{/other_user}","gists_url":"https://api.github.com/users/TheJakeSchmidt/gists{/gist_id}","starred_url":"https://api.github.com/users/TheJakeSchmidt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheJakeSchmidt/subscriptions","organizations_url":"https://api.github.com/users/TheJakeSchmidt/orgs","repos_url":"https://api.github.com/users/TheJakeSchmidt/repos","events_url":"https://api.github.com/users/TheJakeSchmidt/events{/privacy}","received_events_url":"https://api.github.com/users/TheJakeSchmidt/received_events","type":"User","site_admin":false},"created_at":"2015-07-20T17:00:41Z","updated_at":"2015-07-20T17:00:41Z","body":"Sorry, I should have given more detail - I filed this bug report a little too fast. I don't think this is working as intended, for a couple of reasons, but let me know if I'm wrong.\r\n\r\nWhen the program hangs, the subprocess is blocked on a write() call to its stdout file descriptor (according to GDB). I'm pretty sure that's not supposed to happen after output() has been called - the output() call spawns a thread that should consume all the output from the pipe before returning (https://github.com/rust-lang/rust/blob/feba393b8ed60efe79f9f5207fde904d085949f5/src/libstd/process.rs#L533). The hang is expected if status() is called before output(), but not if output() is called first.\r\n\r\nAdditionally, the equivalent Python program works (even with large numbers), so I don't think it's an inherent limitation of the kernel:\r\n\r\n    import subprocess\r\n\r\n    def main():\r\n        proc = subprocess.Popen([\"python\",  \"-c\", \"print('a' * 10000000)\"],\r\n                                shell=False, stdout=subprocess.PIPE)\r\n        proc.communicate()\r\n        print \"Calling wait()\"\r\n        proc.wait()\r\n        print \"wait() returned\"\r\n\r\n    if __name__ == '__main__':\r\n        main()"}}