{"action":"created","issue":{"url":"https://api.github.com/repos/akka/akka/issues/19542","repository_url":"https://api.github.com/repos/akka/akka","labels_url":"https://api.github.com/repos/akka/akka/issues/19542/labels{/name}","comments_url":"https://api.github.com/repos/akka/akka/issues/19542/comments","events_url":"https://api.github.com/repos/akka/akka/issues/19542/events","html_url":"https://github.com/akka/akka/issues/19542","id":127697744,"number":19542,"title":"Akka Http: Nginx proxy error when returning large json payloads","user":{"login":"cmbaxter","id":2078763,"avatar_url":"https://avatars.githubusercontent.com/u/2078763?v=3","gravatar_id":"","url":"https://api.github.com/users/cmbaxter","html_url":"https://github.com/cmbaxter","followers_url":"https://api.github.com/users/cmbaxter/followers","following_url":"https://api.github.com/users/cmbaxter/following{/other_user}","gists_url":"https://api.github.com/users/cmbaxter/gists{/gist_id}","starred_url":"https://api.github.com/users/cmbaxter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmbaxter/subscriptions","organizations_url":"https://api.github.com/users/cmbaxter/orgs","repos_url":"https://api.github.com/users/cmbaxter/repos","events_url":"https://api.github.com/users/cmbaxter/events{/privacy}","received_events_url":"https://api.github.com/users/cmbaxter/received_events","type":"User","site_admin":false},"labels":[{"id":103378704,"url":"https://api.github.com/repos/akka/akka/labels/t:http","name":"t:http","color":"CCCCCC","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/akka/akka/milestones/9","html_url":"https://github.com/akka/akka/milestone/9","labels_url":"https://api.github.com/repos/akka/akka/milestones/9/labels","id":658578,"number":9,"title":"invalid","description":"Used to collect invalid issues so they don't end up in reports.","creator":{"login":"2m","id":422086,"avatar_url":"https://avatars.githubusercontent.com/u/422086?v=3","gravatar_id":"","url":"https://api.github.com/users/2m","html_url":"https://github.com/2m","followers_url":"https://api.github.com/users/2m/followers","following_url":"https://api.github.com/users/2m/following{/other_user}","gists_url":"https://api.github.com/users/2m/gists{/gist_id}","starred_url":"https://api.github.com/users/2m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2m/subscriptions","organizations_url":"https://api.github.com/users/2m/orgs","repos_url":"https://api.github.com/users/2m/repos","events_url":"https://api.github.com/users/2m/events{/privacy}","received_events_url":"https://api.github.com/users/2m/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":257,"state":"open","created_at":"2014-05-14T12:01:02Z","updated_at":"2016-12-12T10:39:04Z","due_on":null,"closed_at":null},"comments":16,"created_at":"2016-01-20T14:46:11Z","updated_at":"2016-12-23T08:52:42Z","closed_at":"2016-01-20T15:07:03Z","body":"As mentioned in this user group post:\n\nhttps://groups.google.com/forum/#!topic/akka-user/aDwaI8Xia74\n\nI'm running into an error using akka http with nginx in front of it as a reverse proxy when I return large (MBs) json payloads.  The error I see in the nginx log is:\n\n```\nupstream prematurely closed connection while reading upstream\n```\n\nI created a very simple route that can reproduce this issue.  That code is as follows:\n\n```\n  pathPrefix(\"api\" / \"proxytest\"){\n    (get & parameters('numberOfA.as[Int], 'chunk.as[Boolean])){ (aNum, chunk) =>  \n      val bunchOfA = (for(i <- 1 to aNum) yield \"a\").mkString\n      val json = s\"\"\"{\"test\": \"$bunchOfA\"}\"\"\"\n\n      val entity = \n        if (chunk){\n          val chunks = Source.single(json).mapConcat(_.grouped(1024*10).toList).map(HttpEntity.Chunk.apply(_))   \n          HttpEntity.Chunked(ContentTypes.`application/json`, chunks)\n        }\n        else{\n          HttpEntity(ContentTypes.`application/json`, json )\n        }\n\n      val response = HttpResponse(StatusCodes.OK, entity = entity)\n      complete(response)\n    }\n  }\n```\n\nIf I test this route with a get request passing in numberOfA as something small, say 500, and chunk as false everything works when I go through nginx.  But if I pass in something large, like 2100000 with chunk set to false, I get that nginx error.  If I pass in chunk=true, everything works.  Also, if I skip nginx and go right to my server, everything works regardless of chunking and size.  I also noticed that I always get this dead letter warning when I hit the nginx error:\n\n```\n[INFO] [01/20/2016 09:42:02.626] [default-akka.actor.default-dispatcher-4] [akka://default/system/IO-TCP/selectors/$a/1] Message [akka.io.SelectionHandler$ChannelWritable$] from Actor[akka://default/deadLetters] to Actor[akka://default/system/IO-TCP/selectors/$a/1#-229858999] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.\n```\n\nThis seems to imply that maybe the connection is closed prematurely in akka http before nginx thinks it's done with it.  \n\nI have also attached my nginx config (version 1.6.2).  Let me know if you need anything more from me.\n[nginx.conf.txt](https://github.com/akka/akka/files/97562/nginx.conf.txt)\n"},"comment":{"url":"https://api.github.com/repos/akka/akka/issues/comments/268958623","html_url":"https://github.com/akka/akka/issues/19542#issuecomment-268958623","issue_url":"https://api.github.com/repos/akka/akka/issues/19542","id":268958623,"user":{"login":"lomigmegard","id":434236,"avatar_url":"https://avatars.githubusercontent.com/u/434236?v=3","gravatar_id":"","url":"https://api.github.com/users/lomigmegard","html_url":"https://github.com/lomigmegard","followers_url":"https://api.github.com/users/lomigmegard/followers","following_url":"https://api.github.com/users/lomigmegard/following{/other_user}","gists_url":"https://api.github.com/users/lomigmegard/gists{/gist_id}","starred_url":"https://api.github.com/users/lomigmegard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lomigmegard/subscriptions","organizations_url":"https://api.github.com/users/lomigmegard/orgs","repos_url":"https://api.github.com/users/lomigmegard/repos","events_url":"https://api.github.com/users/lomigmegard/events{/privacy}","received_events_url":"https://api.github.com/users/lomigmegard/received_events","type":"User","site_admin":false},"created_at":"2016-12-23T08:52:42Z","updated_at":"2016-12-23T08:52:42Z","body":"We stumbled on this issue. The connection is closed when a request is made through nginx (reverse-proxy) and the return entity is large (~800K).\r\nVersions: `Scala 2.11.8`, `Akka 2.4.14`, `Akka HTTP 10.0.0`, `Nginx 1.10.1`.\r\nFrom the nginx logs, the connection is closed by Akka after the data is transmitted. \r\nFrom Akka logs, nothing visible :( no exceptions at all. \r\n\r\nWe didn't find any workaround but to have smaller responses. "}}
{"actor":{"display_login":"lomigmegard"}}