tcp - GOLANG, HTTP having "use of closed network connection" error -


i getting lot of error below mentioned,

read tcp xx.xx.xx.xx:80: use of closed network connection

read tcp xx.xx.xx.xx:80: connection reset peer

//function http connection

func getresponsebytesbyurl_raw(resturl, connectiontimeoutstr, readtimeoutstr string) ([]byte, error) {     connectiontimeout, _ /*err*/ := time.parseduration(connectiontimeoutstr)     readtimeout, _ /*err*/ := time.parseduration(readtimeoutstr)     timeout := connectiontimeout + readtimeout // time.duration((strconv.atoi(connectiontimeoutstr) + strconv.atoi(readtimeoutstr)))     //timeout = 200 * time.millisecond     client := http.client{         timeout: timeout,     }     resp, err := client.get(resturl)     if nil != err {         logger.setlog("error getresponsebytesbyurl_raw |err: ", logs.levelerror, err)         return make([]byte, 0), err     }     defer resp.body.close()     body, err := ioutil.readall(resp.body)     return body, err } 

update (july 14):

server : numcpu=8, ram=24gb, go=go1.4.2.linux-amd64

i getting such error during high traffic. 20000-30000 request per minutes, , have time frame of 500ms fetch response third party api.

netstat status server (using : netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n) frequency

      1 established)       1 foreign       9 listen      33 fin_wait1     338 established    5530 syn_sent   32202 time_wait 

sysctl -p

**sysctl -p** fs.file-max = 2097152 vm.swappiness = 10 vm.dirty_ratio = 60 vm.dirty_background_ratio = 2 net.ipv4.tcp_synack_retries = 2 net.ipv4.ip_local_port_range = 2000 65535 net.ipv4.tcp_rfc1337 = 1 net.ipv4.tcp_fin_timeout = 5 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_keepalive_probes = 5 net.ipv4.tcp_keepalive_intvl = 15 net.core.rmem_default = 31457280 net.core.rmem_max = 12582912 net.core.wmem_default = 31457280 net.core.wmem_max = 12582912 net.core.somaxconn = 65536 net.core.netdev_max_backlog = 65536 net.core.optmem_max = 25165824 net.ipv4.tcp_mem = 65536 131072 262144 net.ipv4.udp_mem = 65536 131072 262144 net.ipv4.tcp_rmem = 8192 87380 16777216 net.ipv4.udp_rmem_min = 16384 net.ipv4.tcp_wmem = 8192 65536 16777216 net.ipv4.udp_wmem_min = 16384 net.ipv4.tcp_max_tw_buckets = 1440000 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_tw_reuse = 1 net.ipv6.bindv6only = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.icmp_echo_ignore_broadcasts = 1 error: "net.ipv4.icmp_ignore_bogus_error_messages" unknown key kernel.exec-shield = 1 kernel.randomize_va_space = 1 net.ipv4.conf.all.log_martians = 1 net.ipv4.conf.default.log_martians = 1 net.ipv4.icmp_ignore_bogus_error_responses = 1 net.ipv4.ip_forward = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 

when making connections @ high rate on internet, it's you're going encounter some connection problems. can't mitigate them completely, may want add retry logic around request. actual error type @ point doesn't matter, matching error string use of closed network connection or connection reset peer best can if want specific. make sure limit retries backoff, systems drop or reset connections way limit request rates, , may more errors faster reconnect.

depending on number of remote hosts you're communicating with, want increase transport.maxidleconnsperhost (the default 2). fewer hosts talk to, higher can set this. decrease number of new connections made, , speed requests overall.

if can, try go1.5 beta. there have been couple changes around keep-alive connections may reduce number of errors see.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -