{"action":"created","issue":{"url":"https://api.github.com/repos/brianc/node-pg-copy-streams/issues/48","repository_url":"https://api.github.com/repos/brianc/node-pg-copy-streams","labels_url":"https://api.github.com/repos/brianc/node-pg-copy-streams/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/brianc/node-pg-copy-streams/issues/48/comments","events_url":"https://api.github.com/repos/brianc/node-pg-copy-streams/issues/48/events","html_url":"https://github.com/brianc/node-pg-copy-streams/issues/48","id":167900335,"number":48,"title":"`finish` emitted before data is copied","user":{"login":"Sequoia","id":317498,"avatar_url":"https://avatars.githubusercontent.com/u/317498?v=3","gravatar_id":"","url":"https://api.github.com/users/Sequoia","html_url":"https://github.com/Sequoia","followers_url":"https://api.github.com/users/Sequoia/followers","following_url":"https://api.github.com/users/Sequoia/following{/other_user}","gists_url":"https://api.github.com/users/Sequoia/gists{/gist_id}","starred_url":"https://api.github.com/users/Sequoia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sequoia/subscriptions","organizations_url":"https://api.github.com/users/Sequoia/orgs","repos_url":"https://api.github.com/users/Sequoia/repos","events_url":"https://api.github.com/users/Sequoia/events{/privacy}","received_events_url":"https://api.github.com/users/Sequoia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-27T16:38:07Z","updated_at":"2016-07-30T00:17:39Z","closed_at":null,"body":"I'm running my code in AWS lambda, wherein you call `done` when you're process is ready to exit.\r\n\r\n```\r\n        /** @type {NodeJS.WritableStream} */\r\n        var pgStream = client.query(copyFrom(copyQuery));\r\n\r\n        csvStream\r\n          .pipe(pgStream)\r\n          .on('error', function(e){\r\n            logerr('pg stream error');\r\n            done(e);\r\n          })\r\n          .on('finish', function(){\r\n            console.timeEnd('query time');\r\n            done(); //////////////// <---- Offending line\r\n          });\r\n```\r\n\r\nThis always exits **before the data is copied**. If I remove `done`, the process won't exit but the data **does copy**. Why is finish getting called before data is streamed? Should I be listening for \"finish\" elsewhere?"},"comment":{"url":"https://api.github.com/repos/brianc/node-pg-copy-streams/issues/comments/236324261","html_url":"https://github.com/brianc/node-pg-copy-streams/issues/48#issuecomment-236324261","issue_url":"https://api.github.com/repos/brianc/node-pg-copy-streams/issues/48","id":236324261,"user":{"login":"jeromew","id":687842,"avatar_url":"https://avatars.githubusercontent.com/u/687842?v=3","gravatar_id":"","url":"https://api.github.com/users/jeromew","html_url":"https://github.com/jeromew","followers_url":"https://api.github.com/users/jeromew/followers","following_url":"https://api.github.com/users/jeromew/following{/other_user}","gists_url":"https://api.github.com/users/jeromew/gists{/gist_id}","starred_url":"https://api.github.com/users/jeromew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeromew/subscriptions","organizations_url":"https://api.github.com/users/jeromew/orgs","repos_url":"https://api.github.com/users/jeromew/repos","events_url":"https://api.github.com/users/jeromew/events{/privacy}","received_events_url":"https://api.github.com/users/jeromew/received_events","type":"User","site_admin":false},"created_at":"2016-07-30T00:17:39Z","updated_at":"2016-07-30T00:17:39Z","body":"What version of pgCopy did you test ?\r\n\r\n`finish` does not give you information on the end of the COPY, simply that all the incoming data has fully entered the copyFrom Stream. It may be still flushing.\r\n\r\n`end` should tell you when the process is finished but we may need to delay it to a later ACK of the database. If you have an error you can reproduce we can try and find the problem.\r\n\r\ncan you try the version that is on this branch ?\r\n\r\nhttps://github.com/jeromew/node-pg-copy-streams/tree/upstream-end\r\n\r\nIn this version the `end` version is delayed after CommandComplete is received.\r\n\r\nYou might also have success with pg-copy-streams@1.1.0 because a modification that occured in 1.1.1 led to `end` being called 2 times : 1 time on CopyDone and 1 time on CommandComplete.\r\n\r\nYou may also try in your code, with the current npm version to call done() but only on the second 'end' received.\r\n\r\nA fix is being discussed on #54 \r\n\r\n"}}
{"actor":{"display_login":"jeromew"}}