2013-08-17 81 views
4

我正在製作一個clojure web應用程序,它使用分塊的HTTP響應將數據傳輸到客戶端。當我在本地使用foreman運行它時,這很好用,但在將它部署到Heroku時無法正常工作。用clojure對Heroku進行HTTP流式傳輸/分塊響應

展示此行爲的最小示例可以找到on my github here。前端(在resources/index.html中)執行AJAX GET請求,並在到達時打印響應塊。服務器使用http-kit每隔一秒向連接的客戶端發送一個新的塊。按照設計,HTTP請求永遠不會完成。

當相同的代碼部署到Heroku時,服務器在發送第一個塊後立即關閉HTTP連接。它似乎是Heroku的路由網格導致這種斷開發生。

$ curl -v http://arcane-headland-2284.herokuapp.com/stream 
* About to connect() to arcane-headland-2284.herokuapp.com port 80 (#0) 
* Trying 54.243.166.168... 
* Adding handle: conn: 0x6c3be0 
* Adding handle: send: 0 
* Adding handle: recv: 0 
* Curl_addHandleToPipeline: length: 1 
* - Conn 0 (0x6c3be0) send_pipe: 1, recv_pipe: 0 
* Connected to arcane-headland-2284.herokuapp.com (54.243.166.168) port 80 (#0) 
> GET /stream HTTP/1.1 
> User-Agent: curl/7.31.0 
> Host: arcane-headland-2284.herokuapp.com 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Content-Type: text/html; charset=utf-8 
< Date: Sat, 17 Aug 2013 16:57:24 GMT 
* Server http-kit is not blacklisted 
< Server: http-kit 
< transfer-encoding: chunked 
< Connection: keep-alive 
< 
* transfer closed with outstanding read data remaining 
* Closing connection 0 
curl: (18) transfer closed with outstanding read data remaining 
The time is currently Sat Aug 17 16:57:24 UTC 2013 <-- this is the first chunk 

任何人都可以說明爲什麼這種情況正在發生:

這也可以通過執行使用curl GET請求見過? HTTP流應該在Heroku的Cedar堆棧中得到支持。代碼正確運行使用foreman這一事實表明它在Heroku的路由網格中導致它斷開。

的失敗項目的現場演示:http://arcane-headland-2284.herokuapp.com/

回答

0

https://devcenter.heroku.com/articles/request-timeout可能是相關的:像你這樣的「長輪詢」請求必須發送數據每55秒被終止。

+1

不幸的是我每秒都會向客戶端發送數據,並且在55秒之前連接被關閉(實際上在第一個塊之後立即響應,即大約1秒) 。我的日誌不包含任何錯誤 - 如果是超時,我希望看到H12。 – rufo