can't assign requested address 錯誤解決
最近一直在寫新版本的beego2,在做MUX測試的時候遇到了這個問題,
BenchmarkBeegoMuxRequests-8 panic: Post http://127.0.0.1:59079/repos/: ... ests: dial tcp 127.0.0.1:59079: connect: can't assign requested address
這個錯誤看上去是我的測試耗掉了所有的local port,但是local port 不應該是複用的嗎?
我的測試裡面的程式碼片段是這樣的:
for _, route := range routes {
res, err := Request(route.method, ts.URL+route.path)
if err != nil {
panic(err)
}
res.Body.Close()
}
這個時候我去翻看了一下response裡面的body的文件
// The default HTTP client's Transport does not
// attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections
// ("keep-alive") unless the Body is read to completion and is
// closed.
大家看到裡面的話,只有當body讀取並關閉,而我上面的程式碼只是關閉了,Body並沒有讀取。所以導致了client沒有reuse TCP connection。
所以這個完全明白了,我們必須在關閉之前完全的讀取Body裡面的資料,我把原來的程式碼改成了下面之後就解決了問題
for _, route := range routes {
res, err := Request(route.method, ts.URL+route.path)
if err != nil {
panic(err)
}
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
}
相關文章
- Dubbo廣播模式下報錯:Can't assign requested address解決辦法模式
- Mac電腦下使用Socket報錯socket丟擲Can’t assign requested address解決Mac
- MySQL錯誤1042-Can't get hostname for your address解決方法MySql
- 【TCP/IP的狀態圖解決Cannot assign requested address】TCP圖解
- Can't Connect to MySQL Server on IP Address (10061) 錯誤的解決方案MySqlServer
- MySQL錯誤1042-Can't get hostname for your addressMySql
- k8s 環境下Cannot assign requested address問題解決K8S
- 解決svnserve: Can't bind server socket: Address already in useServer
- RMAN的"rman: can't open target"錯誤
- Linux下安裝Oracle 錯誤解決 - Error: Can't open display:127.0..0.1:0.0LinuxOracleError
- wget下載安裝時出現錯誤doesn‘t match requested host name錯誤wget
- Window中安裝gitblit時,IP地址或埠衝突,提示Cannot assign requested address: bind的詳細解決方法Git
- json.dumps錯誤:'utf8' codec can't decode byte解決方案JSON
- Supervisor 解決 can't find command *
- 解決can't find -lGL的問題
- cordova 解決can’t not find moudle " plugman platform ios"PlatformiOS
- python報錯問題解決:'ascii' codec can't encode characterPythonASCII
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- 關於收到localhost modprobe: modprobe: Can't locate module ethX的錯誤localhost
- 連線MySQL錯誤:Can't connect to MySQL server (10060)MySqlServer
- linux上“rman can't open target”問題解決Linux
- ERROR L107: ADDRESS SPACE OVERFLOW keil錯誤的解決方法Error
- [mac pip錯誤]Can't connect to HTTPS URL because the SSL module is not availableMacHTTPAI
- 【crontab】“bad minute”及“errors in crontab file, can't install”錯誤處理Error
- eslint --fix 報錯 can't not find modulesEsLint
- MongoDB報錯:"assertion" : "can't map file memory"MongoDB
- Mysql:Variable 'XXXt' can't be set to the value of 'NULL'解決MySqlNull
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- FileZilla:425 Can't open data connection for transfer of解決辦法
- mysql:Variable 'character_set_client' can't be set to the value of 'NULL'解決MySqlclientNull
- Ocelot錯誤解決
- 解決telnet: connect to address 127.0.0.1: Connection refused的錯誤資訊問題127.0.0.1
- Variable 'character_set_client' can't be set to the value of Null的解決方法clientNull
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock錯誤MySqlServer
- Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist解決辦法ErrorMySql
- VIM 常用錯誤解決
- sqldeveloper for windows 錯誤解決SQLDeveloperWindows
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError