英文:
Go retry for 403 forbidden http request?
问题
我从我的Go http请求中得到了这条消息:
&{Status:403 Forbidden StatusCode:403 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Content-Type:[text/html] Content-Length:[345] Date:[Wed, 26 Nov 2014 07:46:36 GMT] Server:[lighttpd]] Body:0xc2155b4860 ContentLength:345 TransferEncoding:[] Close:true Trailer:map[] Request:0xc2160829c0 TLS:0xc21604eb00}
我使用以下代码发送请求:
resp, err := client.Do(req)
if resp.StatusCode > 400 {
我的代码本应只是重新尝试请求,使用与接收到此禁止消息不同的httpclient
进行初始化。但是我收到了这条消息:
goroutine 780 [IO wait, 479 minutes]:
net.(*pollDesc).Wait(0xc2082b6a00, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(*pollDesc).WaitRead(0xc2082b6a00, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(*netFD).Read(0xc2082b69a0, 0xc2080e5000, 0x1000, 0x1000, 0x0, 0x7fd302e42fd8, 0xc20c8359a0)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(*conn).Read(0xc2080c20d8, 0xc2080e5000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
crypto/tls.(*block).readFromUntil(0xc2081c0f60, 0x7fd302e44538, 0xc2080c20d8, 0x5, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:454 +0xe6
crypto/tls.(*Conn).readRecord(0xc2082a6840, 0x17, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:539 +0x2da
crypto/tls.(*Conn).Read(0xc2082a6840, 0xc2082e3000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:904 +0x166
net/http.noteEOFReader.Read(0x7fd302e48ee8, 0xc2082a6840, 0xc20805d238, 0xc2082e3000, 0x1000, 0x1000, 0x7612c0, 0x0, 0x0)
/usr/local/go/src/net/http/transport.go:1270 +0x6e
net/http.(*noteEOFReader).Read(0xc2081701e0, 0xc2082e3000, 0x1000, 0x1000, 0xc208014400, 0x0, 0x0)
<autogenerated>:125 +0xd4
bufio.(*Reader).fill(0xc2082cf620)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(*Reader).Peek(0xc2082cf620, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0xf0
net/http.(*persistConn).readLoop(0xc20805d1e0)
/usr/local/go/src/net/http/transport.go:842 +0xa4
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
goroutine 17 [syscall, 489 minutes, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
goroutine 798 [IO wait, 479 minutes]:
net.(*pollDesc).Wait(0xc2082b6a70, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(*pollDesc).WaitRead(0xc2082b6a70, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(*netFD).Read(0xc2082b6a10, 0xc2080e4000, 0x1000, 0x1000, 0x0, 0x7fd302e42fd8, 0xc20c8359b0)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(*conn).Read(0xc2080c20b8, 0xc2080e4000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
crypto/tls.(*block).readFromUntil(0xc2081ef5f0, 0x7fd302e44538, 0xc2080c20b8, 0x5, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:454 +0xe6
crypto/tls.(*Conn).readRecord(0xc2082a6580, 0x17, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:539 +0x2da
crypto/tls.(*Conn).Read(0xc2082a6580, 0xc20828d000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:904 +0x166
net/http.noteEOFReader.Read(0x7fd302e48ee8, 0xc2082a6580, 0xc208248cb8, 0xc20828d000, 0x1000, 0x1000, 0x7612c0, 0x0, 0x0)
/usr/local/go/src/net/http/transport.go:1270 +0x6e
net/http.(*noteEOFReader).Read(0xc208167300, 0xc20828d000, 0x1000, 0x1000, 0xc208014400, 0x0, 0x0)
<autogenerated>:125 +0xd4
bufio.(*Reader).fill(0xc208132c60)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(*Reader).Peek(0xc208132c60, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0xf0
net/http.(*persistConn).readLoop(0xc208248c60)
/usr/local/go/src/net/http/transport.go:842 +0xa4
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
goroutine 9904 [select, 57 minutes]:
net/http.(*persistConn).readLoop(0xc21629a8f0)
/usr/local/go/src/net/http/transport.go:928 +0x9ce
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
goroutine 799 [select, 479 minutes]:
net/http.(*persistConn).writeLoop(0xc208248c60)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 781 [select, 479 minutes]:
net/http.(*persistConn).writeLoop(0xc20805d1e0)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 9905 [select, 57 minutes]:
net/http.(*persistConn).writeLoop(0xc21629a8f0)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 10958 [runnable]:
net/http.(*persistConn).writeLoop(0xc217483810)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 10957 [runnable]:
net/http.(*persistConn).readLoop(0xc217483810)
/usr/local/go/src/net/http/transport.go:928 +0x9ce
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
这是什么意思?是超时了吗?我不知道从哪里开始调试...
英文:
I got this message from my Go http request:
&{Status:403 Forbidden StatusCode:403 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Content-Type:[text/html] Content-Length:[345] Date:[Wed, 26 Nov 2014 07:46:36 GMT] Server:[lighttpd]] Body:0xc2155b4860 ContentLength:345 TransferEncoding:[] Close:true Trailer:map[] Request:0xc2160829c0 TLS:0xc21604eb00}
I send request with this:
resp, err := client.Do(req)
if resp.StatusCode > 400 {
And my code was supposed to just retry the request initializing the httpclient
different than the one that gets this forbidden message. And I get this message:
goroutine 780 [IO wait, 479 minutes]:
net.(*pollDesc).Wait(0xc2082b6a00, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(*pollDesc).WaitRead(0xc2082b6a00, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(*netFD).Read(0xc2082b69a0, 0xc2080e5000, 0x1000, 0x1000, 0x0, 0x7fd302e42fd8, 0xc20c8359a0)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(*conn).Read(0xc2080c20d8, 0xc2080e5000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
crypto/tls.(*block).readFromUntil(0xc2081c0f60, 0x7fd302e44538, 0xc2080c20d8, 0x5, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:454 +0xe6
crypto/tls.(*Conn).readRecord(0xc2082a6840, 0x17, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:539 +0x2da
crypto/tls.(*Conn).Read(0xc2082a6840, 0xc2082e3000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:904 +0x166
net/http.noteEOFReader.Read(0x7fd302e48ee8, 0xc2082a6840, 0xc20805d238, 0xc2082e3000, 0x1000, 0x1000, 0x7612c0, 0x0, 0x0)
/usr/local/go/src/net/http/transport.go:1270 +0x6e
net/http.(*noteEOFReader).Read(0xc2081701e0, 0xc2082e3000, 0x1000, 0x1000, 0xc208014400, 0x0, 0x0)
<autogenerated>:125 +0xd4
bufio.(*Reader).fill(0xc2082cf620)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(*Reader).Peek(0xc2082cf620, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0xf0
net/http.(*persistConn).readLoop(0xc20805d1e0)
/usr/local/go/src/net/http/transport.go:842 +0xa4
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
goroutine 17 [syscall, 489 minutes, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
goroutine 798 [IO wait, 479 minutes]:
net.(*pollDesc).Wait(0xc2082b6a70, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:84 +0x47
net.(*pollDesc).WaitRead(0xc2082b6a70, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:89 +0x43
net.(*netFD).Read(0xc2082b6a10, 0xc2080e4000, 0x1000, 0x1000, 0x0, 0x7fd302e42fd8, 0xc20c8359b0)
/usr/local/go/src/net/fd_unix.go:242 +0x40f
net.(*conn).Read(0xc2080c20b8, 0xc2080e4000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:121 +0xdc
crypto/tls.(*block).readFromUntil(0xc2081ef5f0, 0x7fd302e44538, 0xc2080c20b8, 0x5, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:454 +0xe6
crypto/tls.(*Conn).readRecord(0xc2082a6580, 0x17, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:539 +0x2da
crypto/tls.(*Conn).Read(0xc2082a6580, 0xc20828d000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:904 +0x166
net/http.noteEOFReader.Read(0x7fd302e48ee8, 0xc2082a6580, 0xc208248cb8, 0xc20828d000, 0x1000, 0x1000, 0x7612c0, 0x0, 0x0)
/usr/local/go/src/net/http/transport.go:1270 +0x6e
net/http.(*noteEOFReader).Read(0xc208167300, 0xc20828d000, 0x1000, 0x1000, 0xc208014400, 0x0, 0x0)
<autogenerated>:125 +0xd4
bufio.(*Reader).fill(0xc208132c60)
/usr/local/go/src/bufio/bufio.go:97 +0x1ce
bufio.(*Reader).Peek(0xc208132c60, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0xf0
net/http.(*persistConn).readLoop(0xc208248c60)
/usr/local/go/src/net/http/transport.go:842 +0xa4
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
goroutine 9904 [select, 57 minutes]:
net/http.(*persistConn).readLoop(0xc21629a8f0)
/usr/local/go/src/net/http/transport.go:928 +0x9ce
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
goroutine 799 [select, 479 minutes]:
net/http.(*persistConn).writeLoop(0xc208248c60)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 781 [select, 479 minutes]:
net/http.(*persistConn).writeLoop(0xc20805d1e0)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 9905 [select, 57 minutes]:
net/http.(*persistConn).writeLoop(0xc21629a8f0)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 10958 [runnable]:
net/http.(*persistConn).writeLoop(0xc217483810)
/usr/local/go/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:661 +0xcbc
goroutine 10957 [runnable]:
net/http.(*persistConn).readLoop(0xc217483810)
/usr/local/go/src/net/http/transport.go:928 +0x9ce
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:660 +0xc9f
What does it mean? Is it timing out? I have no clue where to start debugging...
答案1
得分: 2
我遇到了这个问题。这基本上意味着你已经达到了每个进程打开文件的最大数量。对于Linux来说,大约是1024个。在Go语言中,这是一件非常容易的事情,因为你可以拥有成千上万个Go协程。
请注意,你会为很多东西打开文件:
=> 实际的日志文件
=> /dev文件
=> UNIX套接字
=> 网络套接字
=> 库文件/lib /lib64
=> 可执行文件和其他程序等
英文:
I have encountered this problem. This basically means that you have reached the maximum amount of opened files per process. For Linux it is around 1024. This is a very easy thing to do with go since you can have hundreds of thousands of go routines.
Please note that you open files for a lot of stuff -
=> Actual log file
=> /dev files
=> UNIX Sockets
=> Network sockets
=> Library files /lib /lib64
=> Executables and other programs etc
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论