一個超長時間的http api 的 nginx 超時錯誤 java.io.IOException: unexpected end of stream on Connection

一個長時間的http api 的 nginx 超時錯誤

直接訪問IP是OK的。但是經(jīng)過了中間一臺域名機子,配置了nginx (基本上所有的超時時間timeout配置項都配置了足夠的時間)的proxy_pass到這個IP上。

用瀏覽器方式http api 舶掖, 等待之后可以正確返回response。

但是,用下面的Kotlin代碼的這個get方法調(diào)用:


fun get(url: String): String? {
    var result: String? = ""
    val okhttp = OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.MINUTES)
            .readTimeout(10, TimeUnit.MINUTES)
            .writeTimeout(10, TimeUnit.MINUTES)
            .build()

    val request = Request.Builder()
            .url(url)
            .addHeader("Connection","close")
            .build()

    val call = okhttp.newCall(request)

    try {
        val response = call.execute()
        result = response.body()?.string()
        println(result)

    } catch (e: IOException) {
        e.printStackTrace()
    }

    return result
}

出錯日志:

{"message":"H5Agent hasRunningInstance is false","runningInstance":false}

java.io.IOException: unexpected end of stream on Connection{h5agent.alibaba.net:80, proxy=DIRECT hostAddress=h5agent.alibaba.net/42.156.238.36:80 cipherSuite=none protocol=http/1.1}
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:203)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at com.easy.kotlin.HttpClientKt.get(HttpClient.kt:36)
    at com.easy.kotlin.HttpClientKt.main(HttpClient.kt:16)
Caused by: java.io.EOFException: \n not found: limit=0 content=…
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:227)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:187)
    ... 17 more


用下面的Kotlin代碼getAsync函數(shù)調(diào)用:



fun getAsync(url: String) {
    val okhttp = OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.MINUTES)
            .readTimeout(10, TimeUnit.MINUTES)
            .writeTimeout(10, TimeUnit.MINUTES)
            .build()

    val request = Request.Builder()
            .url(url)
            .build()

    val call = okhttp.newCall(request)

    call.enqueue(object : Callback {
        override fun onFailure(call: Call, e: IOException) {
            println(e.message)
            e.printStackTrace()
        }

        override fun onResponse(call: Call, response: Response) {
            try {
                val result = response.body()?.string()
                println(result)
            } catch (e: IOException) {
                println("response = ${response}")
                e.printStackTrace()
            }
        }
    })

}



也是拋錯:

{"message":"H5Agent hasRunningInstance is false","runningInstance":false}
unexpected end of stream on Connection{h5agent.alibaba.net:80, proxy=DIRECT hostAddress=h5agent.alibaba.net/42.156.238.36:80 cipherSuite=none protocol=http/1.1}
java.io.IOException: unexpected end of stream on Connection{h5agent.alibaba.net:80, proxy=DIRECT hostAddress=h5agent.alibaba.net/42.156.238.36:80 cipherSuite=none protocol=http/1.1}
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:203)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException: \n not found: limit=0 content=…
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:227)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:187)
    ... 19 more

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末奠货,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子粘优,更是在濱河造成了極大的恐慌仇味,老刑警劉巖呻顽,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異丹墨,居然都是意外死亡廊遍,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進店門贩挣,熙熙樓的掌柜王于貴愁眉苦臉地迎上來喉前,“玉大人,你說我怎么就攤上這事王财÷延兀” “怎么了?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵绒净,是天一觀的道長见咒。 經(jīng)常有香客問我,道長挂疆,這世上最難降的妖魔是什么改览? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮缤言,結(jié)果婚禮上宝当,老公的妹妹穿的比我還像新娘。我一直安慰自己胆萧,他們只是感情好庆揩,可當我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著跌穗,像睡著了一般订晌。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上蚌吸,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天腾仅,我揣著相機與錄音,去河邊找鬼套利。 笑死推励,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的肉迫。 我是一名探鬼主播验辞,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼喊衫!你這毒婦竟也來了跌造?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎壳贪,沒想到半個月后陵珍,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡违施,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年互纯,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片磕蒲。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡留潦,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出辣往,到底是詐尸還是另有隱情兔院,我是刑警寧澤,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布站削,位于F島的核電站暖眼,受9級特大地震影響无蜂,放射性物質(zhì)發(fā)生泄漏匙监。R本人自食惡果不足惜完残,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一涵叮、第九天 我趴在偏房一處隱蔽的房頂上張望滤奈。 院中可真熱鬧狈定,春花似錦苫拍、人聲如沸睦袖。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽馅笙。三九已至伦乔,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間董习,已是汗流浹背烈和。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留皿淋,地道東北人招刹。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像窝趣,于是被迫代替她去往敵國和親疯暑。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理哑舒,服務發(fā)現(xiàn)妇拯,斷路器,智...
    卡卡羅2017閱讀 134,656評論 18 139
  • 第一章 Nginx簡介 Nginx是什么 沒有聽過Nginx洗鸵?那么一定聽過它的“同行”Apache吧越锈!Ngi...
    JokerW閱讀 32,674評論 24 1,002
  • 1. Nginx的模塊與工作原理 Nginx由內(nèi)核和模塊組成仗嗦,其中,內(nèi)核的設計非常微小和簡潔甘凭,完成的工作也非常簡單...
    rosekissyou閱讀 10,214評論 5 124
  • 《老男孩Linux運維》筆記 隱藏Nginx軟件版本號 一般來說稀拐,軟件的漏洞都和版本有關。因此要盡量隱藏對訪問用戶...
    Zhang21閱讀 3,642評論 0 28
  • 流浪了很久对蒲,心靈一直在漂泊钩蚊。 不斷嘗試,不停碰壁蹈矮,不知道自己想要的是什么砰逻。 很多年后,再回首時泛鸟,不知是怎樣一副表情...
    丞玄閱讀 139評論 0 1