{"action":"created","issue":{"url":"https://api.github.com/repos/awslabs/aws-sdk-cpp/issues/58","labels_url":"https://api.github.com/repos/awslabs/aws-sdk-cpp/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/awslabs/aws-sdk-cpp/issues/58/comments","events_url":"https://api.github.com/repos/awslabs/aws-sdk-cpp/issues/58/events","html_url":"https://github.com/awslabs/aws-sdk-cpp/issues/58","id":121042562,"number":58,"title":"FileStream should flush on network operation complete","user":{"login":"cjhanks","id":1406887,"avatar_url":"https://avatars.githubusercontent.com/u/1406887?v=3","gravatar_id":"","url":"https://api.github.com/users/cjhanks","html_url":"https://github.com/cjhanks","followers_url":"https://api.github.com/users/cjhanks/followers","following_url":"https://api.github.com/users/cjhanks/following{/other_user}","gists_url":"https://api.github.com/users/cjhanks/gists{/gist_id}","starred_url":"https://api.github.com/users/cjhanks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjhanks/subscriptions","organizations_url":"https://api.github.com/users/cjhanks/orgs","repos_url":"https://api.github.com/users/cjhanks/repos","events_url":"https://api.github.com/users/cjhanks/events{/privacy}","received_events_url":"https://api.github.com/users/cjhanks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-08T16:19:04Z","updated_at":"2015-12-14T07:49:50Z","closed_at":null,"body":"In gist I have code like this..\r\n\r\n```\r\nstd::string filePath = \"some/local/path\";\r\nstd::shared_ptr<Aws::Http::HttpRequest>  request;\r\nrequest->SetResponseStreamFactory(\r\n        [&filePath, &offset]() -> Aws::IOStream* {\r\n            constexpr auto OpenFlag = std::ios_base::out\r\n                                    | std::ios_base::binary;\r\n            Aws::IOStream* ofs =\r\n                Aws::New<Aws::FStream>(ALLOCATION_TAG, filePath, OpenFlag);\r\n            CHECK(ofs->good());\r\n            CHECK(ofs->seekp(offset, ofs->beg));\r\n            return ofs;\r\n        });\r\n\r\nstd::shared_ptr<Aws::Http::HttpResponse> response(std::move(m_client->MakeRequest(*request)));\r\n\r\nstd::ifstream ifs(filePath); // ! DATA NOT YET FLUSHED TO FILE HERE\r\n```\r\n\r\nHowever if I artificially scope everything as follows...\r\n```\r\nstd::string filePath = \"some/local/path\";\r\n{ // BEGIN BOGUS SCOPE\r\nstd::shared_ptr<Aws::Http::HttpRequest>  request;\r\nrequest->SetResponseStreamFactory(\r\n        [&filePath, &offset]() -> Aws::IOStream* {\r\n            constexpr auto OpenFlag = std::ios_base::out\r\n                                    | std::ios_base::binary;\r\n            Aws::IOStream* ofs =\r\n                Aws::New<Aws::FStream>(ALLOCATION_TAG, filePath, OpenFlag);\r\n            CHECK(ofs->good());\r\n            CHECK(ofs->seekp(offset, ofs->beg));\r\n            return ofs;\r\n        });\r\n\r\nstd::shared_ptr<Aws::Http::HttpResponse> response(std::move(m_client->MakeRequest(*request)));\r\n} // END BOGUS SCOPE \r\n\r\nstd::ifstream ifs(filePath); // DATA IS NOW FLUSHED\r\n```\r\n\r\nThis indicates to me a few things:\r\n-  You're not flushing the file stream.\r\n-  You're lazily deleting the Aws::IOstream object\r\n\r\nThis behavior is surprising and cost me ~45 minute of debug time.\r\n\r\nThis may /seem obvious/ in this contrived example.  But the entire AWS SDK is designed using *shared pointers practically everywhere*, and as such... it can be come less clear in complicated code what the precise lifetime of objects will be."},"comment":{"url":"https://api.github.com/repos/awslabs/aws-sdk-cpp/issues/comments/164370912","html_url":"https://github.com/awslabs/aws-sdk-cpp/issues/58#issuecomment-164370912","issue_url":"https://api.github.com/repos/awslabs/aws-sdk-cpp/issues/58","id":164370912,"user":{"login":"cjhanks","id":1406887,"avatar_url":"https://avatars.githubusercontent.com/u/1406887?v=3","gravatar_id":"","url":"https://api.github.com/users/cjhanks","html_url":"https://github.com/cjhanks","followers_url":"https://api.github.com/users/cjhanks/followers","following_url":"https://api.github.com/users/cjhanks/following{/other_user}","gists_url":"https://api.github.com/users/cjhanks/gists{/gist_id}","starred_url":"https://api.github.com/users/cjhanks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjhanks/subscriptions","organizations_url":"https://api.github.com/users/cjhanks/orgs","repos_url":"https://api.github.com/users/cjhanks/repos","events_url":"https://api.github.com/users/cjhanks/events{/privacy}","received_events_url":"https://api.github.com/users/cjhanks/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T07:49:50Z","updated_at":"2015-12-14T07:49:50Z","body":"I believe this is resolved.  Tested version `0.9-504-g39e3893`"}}