parnurzeal / gorequest

GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent )
http://parnurzeal.github.io/gorequest/
MIT License
3.44k stars 414 forks source link

SuperAgent can not be reused when I have many gorouting #73

Open rogerdehe opened 8 years ago

rogerdehe commented 8 years ago

I want to reuse gorequest.SuperAgent in my program, so I new a req, then I always reuse this.This does work at most time,

But when I have multiple goroutine in linux, this just got nil pointer dereference error.Anyway, if I new a SuperAgent, this is not a problem.And also, something strange is that I just run everything well in my Mac, but not ok in linux.

I upload my source code in a txt file. test_http.txt

Here is the stack trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x45c974]

goroutine 932 [running]:
github.com/parnurzeal/gorequest.(*SuperAgent).Timeout.func1(0x747008, 0x3, 0x78a687, 0x11, 0x0, 0x0, 0x0, 0x0)
    /home/roger/golang/src/github.com/parnurzeal/gorequest/main.go:374 +0x18b
net/http.(*Transport).dial(0xc8200181b0, 0x747008, 0x3, 0x78a687, 0x11, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/net/http/transport.go:499 +0x79
net/http.(*Transport).dialConn(0xc8200181b0, 0x0, 0x78a680, 0x4, 0x78a687, 0x11, 0xc8200b0f50, 0x0, 0x0)
    /usr/local/go/src/net/http/transport.go:596 +0x19a9
net/http.(*Transport).getConn.func4(0xc8200181b0, 0x0, 0x78a680, 0x4, 0x78a687, 0x11, 0xc82039daa0)
    /usr/local/go/src/net/http/transport.go:549 +0x66
created by net/http.(*Transport).getConn
    /usr/local/go/src/net/http/transport.go:551 +0x265

goroutine 1 [runnable]:
syscall.Syscall(0x1, 0x1, 0xc820116240, 0x2, 0x2, 0x2, 0x0)
    /usr/local/go/src/syscall/asm_linux_amd64.s:18 +0x5
syscall.write(0x1, 0xc820116240, 0x2, 0x60, 0xc820127d68, 0x0, 0x0)
    /usr/local/go/src/syscall/zsyscall_linux_amd64.go:1064 +0x5f
syscall.Write(0x1, 0xc820116240, 0x2, 0x60, 0x0, 0x0, 0x0)
    /usr/local/go/src/syscall/syscall_unix.go:176 +0x4d
os.(*File).write(0xc82002e010, 0xc820116240, 0x2, 0x60, 0x0, 0x0, 0x0)
    /usr/local/go/src/os/file_unix.go:232 +0xaa
os.(*File).Write(0xc82002e010, 0xc820116240, 0x2, 0x60, 0xc820200101, 0x0, 0x0)
    /usr/local/go/src/os/file.go:139 +0x8a
fmt.Fprintln(0x7f9173307358, 0xc82002e010, 0xc820127f30, 0x1, 0x1, 0x40c760, 0x0, 0x0)
    /usr/local/go/src/fmt/print.go:255 +0xa5
fmt.Println(0xc820127f30, 0x1, 0x1, 0x670a20, 0x0, 0x0)
    /usr/local/go/src/fmt/print.go:264 +0x73
main.main()
    /home/roger/test/test_http.go:67 +0x255
wangming1993 commented 8 years ago

Same with you, and when I upgrade to go1.6+, I met the problem: fatal error: concurrent map read and map

vvelikodny commented 8 years ago

@rogerdehe @wangming1993 you can't use one SuperAgent concurrently, look at Get, Post implementation.

tobyma commented 7 years ago

In MeasureZhiji function,use gorequest.New to new a instance