{"action":"created","issue":{"url":"https://api.github.com/repos/apocas/dockerode/issues/136","labels_url":"https://api.github.com/repos/apocas/dockerode/issues/136/labels{/name}","comments_url":"https://api.github.com/repos/apocas/dockerode/issues/136/comments","events_url":"https://api.github.com/repos/apocas/dockerode/issues/136/events","html_url":"https://github.com/apocas/dockerode/issues/136","id":77577365,"number":136,"title":"how to close stdin ","user":{"login":"dcolens","id":1196562,"avatar_url":"https://avatars.githubusercontent.com/u/1196562?v=3","gravatar_id":"","url":"https://api.github.com/users/dcolens","html_url":"https://github.com/dcolens","followers_url":"https://api.github.com/users/dcolens/followers","following_url":"https://api.github.com/users/dcolens/following{/other_user}","gists_url":"https://api.github.com/users/dcolens/gists{/gist_id}","starred_url":"https://api.github.com/users/dcolens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcolens/subscriptions","organizations_url":"https://api.github.com/users/dcolens/orgs","repos_url":"https://api.github.com/users/dcolens/repos","events_url":"https://api.github.com/users/dcolens/events{/privacy}","received_events_url":"https://api.github.com/users/dcolens/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/apocas/dockerode/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-05-18T09:22:56Z","updated_at":"2015-05-19T14:40:53Z","closed_at":null,"body":"I'm trying to create a container, launch a process (let's say 'wc -c' for the example), send data to its stdin and read the response (number of bytes in this example).\r\n\r\nIt all works fine if I use:\r\n```\r\n      optsc.AttachStdin = true;\r\n      optsc.AttachStout = true;\r\n      optsc.AttachSterr = true;\r\n      optsc.Tty = true;\r\n      optsc.OpenStdin = true;\r\n```\r\nas long as the data written to stdin is less than 4096 bytes, after that it goes wrong, i.e. wc returns \"1\" when I send 4097 bytes. I also tried writing by smaller chunks using a bufferstream to respect the stream's readiness.\r\n\r\nI tried not using tty=true, but in that case I can't figure how to send EOT to stdin and the command never exits. I tried using writing '\\n\\x04', using stream.end or stream.destroy as per #53 without success.\r\n\r\nI guess I'm not doing this right, but not too sure how, the example uses the tty=true, the unit test does not use EOT (it uses bash's exit command).\r\n\r\n\r\nsample code (based on the mocha unit tests) to reproduce the issue :\r\n```\r\n    it(\"should support attach with stdin enable\", function(done) {\r\n      this.timeout(120000);\r\n\r\n      var length = 4096; //set to 4095 to see it working fine, note that stdin will be 1char longer because of the terminating `\\nctrl+d`\r\n\r\n      function randomString(length) {\r\n        var result = '', chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\r\n        for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];\r\n        return result;\r\n      }\r\n\r\n      function handler(err, container) {\r\n        expect(err).to.be.null;\r\n        expect(container).to.be.ok;\r\n\r\n        var attach_opts = {\r\n          stream: true,\r\n          stdin: true,\r\n          stdout: true,\r\n          stderr: true\r\n        };\r\n        container.attach(attach_opts, function handler(err, stream) {\r\n          expect(err).to.be.null;\r\n          expect(stream).to.be.ok;\r\n\r\n          var memStream = new MemoryStream();\r\n          var output = '';\r\n          memStream.on('data', function(data) {\r\n            output += data.toString();\r\n          });\r\n          memStream.on('end', function(data) {\r\n            console.log('memStream.end');\r\n          });\r\n          stream.pipe(memStream);\r\n\r\n          \r\n          \r\n          container.start(function(err, data) {\r\n            expect(err).to.be.null;\r\n            stream.write(randomString(length)+'\\n\\x04');\r\n\r\n            container.wait(function(err, data) {\r\n              expect(err).to.be.null;\r\n              expect(data).to.be.ok;\r\n              output = output.trim();\r\n              console.log('received:'+output);\r\n              expect(output).to.match(new RegExp('.*'+(length+1)+'$'));\r\n              done();\r\n            });\r\n          });      \r\n        });\r\n      }\r\n\r\n      optsc.AttachStdin = true;\r\n      optsc.AttachStout = true;\r\n      optsc.AttachSterr = true;\r\n      optsc.Tty = true\r\n      optsc.OpenStdin = true;\r\n\r\n      optsc.Cmd = ['wc', '-c'];\r\n\r\n      docker.createContainer(optsc, handler);\r\n    });\r\n```\r\n\r\nAny sample code that would allow me to run 'wc -c', sending more than 4096 bytes to stdin and reading the number of bytes from stdout would be great :)\r\n\r\nDid\r\n"},"comment":{"url":"https://api.github.com/repos/apocas/dockerode/issues/comments/103529385","html_url":"https://github.com/apocas/dockerode/issues/136#issuecomment-103529385","issue_url":"https://api.github.com/repos/apocas/dockerode/issues/136","id":103529385,"user":{"login":"apocas","id":597413,"avatar_url":"https://avatars.githubusercontent.com/u/597413?v=3","gravatar_id":"","url":"https://api.github.com/users/apocas","html_url":"https://github.com/apocas","followers_url":"https://api.github.com/users/apocas/followers","following_url":"https://api.github.com/users/apocas/following{/other_user}","gists_url":"https://api.github.com/users/apocas/gists{/gist_id}","starred_url":"https://api.github.com/users/apocas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apocas/subscriptions","organizations_url":"https://api.github.com/users/apocas/orgs","repos_url":"https://api.github.com/users/apocas/repos","events_url":"https://api.github.com/users/apocas/events{/privacy}","received_events_url":"https://api.github.com/users/apocas/received_events","type":"User","site_admin":false},"created_at":"2015-05-19T14:40:53Z","updated_at":"2015-05-19T14:40:53Z","body":"I'm using end in production without any problems since it was implemented in https://github.com/apocas/dockerode/issues/53, although can't confirm Docker versions or anything right now.\r\n\r\nWhen I have time I will try to reproduce your example. Don't know when it will be.\r\n\r\nIf you are in a hurry try to do some debug in https://github.com/apocas/docker-modem/blob/master/lib/http_duplex.js to get some details on the issue, since stdin is managed in here."}}