Runtime error: invalid memory address or nil pointer reference
From last couple of days, hoverfly has been crashing continuously and intermittently with following error logs:
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0xfc90f]
goroutine 1103 [running]: panic(0x4bed00, 0xc82000c0b0) /usr/local/go/src/runtime/panic.go:481 +0x3e6 github.com/SpectoLabs/hoverfly/core.(_Hoverfly).captureRequest(0xc820163340, 0x0, 0x55bd50, 0x0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:313 +0x12cf github.com/SpectoLabs/hoverfly/core.(_Hoverfly).processRequest(0xc820163340, 0xc82064e1c0, 0xc82002aab8, 0x1) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:203 +0xb6 github.com/SpectoLabs/hoverfly/core.NewProxy.func2(0xc82064e1c0, 0xc820bb2000, 0xc820bb2000, 0x1) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/proxy.go:51 +0x2a github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc820da36e0, 0xc82064e1c0, 0xc820bb2000, 0xc5001, 0xc820b4a0a0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x30 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ReqProxyConds).Do.func1(0xc82064e1c0, 0xc820bb2000, 0x11, 0x2f3501) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/dispatcher.go:200 +0x141 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc8207869e0, 0xc82064e1c0, 0xc820bb2000, 0x0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x30 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).filterRequest(0xc820014400, 0xc82064e1c0, 0xc820bb2000, 0xc82064e1c0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/proxy.go:56 +0xc7 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).handleHttps.func1(0xa2ef00, 0xc820894060, 0xc82086a000, 0xc820bb2000, 0xc820cca1c0, 0xc820014400) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:184 +0x891 created by github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).handleHttps /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:236 +0xe7a
Hey @subodhbrahmi,
Thanks for raising the issue. I have a few questions before I can start thoroughly investigating this issue.
- What platform/architecture are you running on?
- Are you using a prebuilt binary or building from source yourself?
- Is there anything you are doing that triggers this or is this happening without any interaction?
Thank you benjih for looking into this. Please see the answers to your questions below:
- MacOS X 10.11.5. I am using it to capture REST/JSON calls
- I am using a prebuild binary v0.8.0
- It has crashed few times while just sitting there in capture mode and another time while actually capturing the services
I hope i have answered the questions to your satisfaction. Please let me know if you need additional details
Hi @subodhbrahmi, I'm running Hoverfly on MacOS X 10.11.6 and unfortunately can't recreate the issue.
Are you running anything else that could interfere with Hoverfly, or are running the application using something that is resource-constraining like a VM or Docker? (I notice 'ubuntu' in the stack trace?)
Now that you point out the ubuntu part of the panic @daniel-bryant-uk, it made me remember.
/home/ubuntu/.go_workspace is the $GOPATH of the Circle CI build.
Another crash while in the capture mode:
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0xfc90f]
goroutine 612 [running]: panic(0x4bed00, 0xc8200100b0) /usr/local/go/src/runtime/panic.go:481 +0x3e6 github.com/SpectoLabs/hoverfly/core.(_Hoverfly).captureRequest(0xc820163340, 0x0, 0x55bd50, 0x0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:313 +0x12cf github.com/SpectoLabs/hoverfly/core.(_Hoverfly).processRequest(0xc820163340, 0xc8200ecc40, 0xc82002eca8, 0x1) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:203 +0xb6 github.com/SpectoLabs/hoverfly/core.NewProxy.func2(0xc8200ecc40, 0xc820212320, 0xc820212320, 0x1) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/proxy.go:51 +0x2a github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc8205e1a80, 0xc8200ecc40, 0xc820212320, 0xc5001, 0xc82014f900) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x30 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ReqProxyConds).Do.func1(0xc8200ecc40, 0xc820212320, 0x12, 0x2f3501) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/dispatcher.go:200 +0x141 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc820112cc0, 0xc8200ecc40, 0xc820212320, 0x0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x30 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).filterRequest(0xc820018600, 0xc8200ecc40, 0xc820212320, 0xc8200ecc40, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/proxy.go:56 +0xc7 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).handleHttps.func1(0x2bbfe10, 0xc82039e040, 0xc8202d9400, 0xc820212320, 0xc820e76380, 0xc820018600) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:184 +0x891 created by github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).handleHttps /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:236 +0xe7a
hi @subodhbrahmi :) Could you also provide an example (doesn't have to be the real thing) of what are you trying to capture? A bit more details would be helpful like whether it's HTTP or HTTPS (cause if it's https then it involves hijacking connection), request info like query, body and then response.
Hello @rusenask, I am actually running the multiple queries as part of automation suite. Most of them are HTTPS.
HI @subodhbrahmi
Are all the queries failing? Or could it be one request/response you are seeing failing?
Can you provide request info for one of the failures: query & body and response ?
Does the problem happen standalone? That is, outside of the automation suite?
Happened again today. At this point i am declaring it unusable for me:
{"error":"Get https://cts-secure.channelintelligence.com:443/841068_confirmation.js: dial tcp: lookup cts-secure.channelintelligence.com on 10.32.235.182:53: no such host","host":"cts-secure.channelintelligence.com","level":"error","method":"GET","mode":"capture","msg":"could not forward request, failed to do an HTTP request.","path":"/841068_confirmation.js","time":"2016-09-30T12:16:34-05:00"} {"error":"Get https://cts-secure.channelintelligence.com:443/841068_confirmation.js: dial tcp: lookup cts-secure.channelintelligence.com on 10.32.235.182:53: no such host","level":"error","mode":"capture","msg":"Got error when reading body after being modified by middleware","time":"2016-09-30T12:16:34-05:00"} panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0xfc90f]
goroutine 1780 [running]: panic(0x4bed00, 0xc8200100b0) /usr/local/go/src/runtime/panic.go:481 +0x3e6 github.com/SpectoLabs/hoverfly/core.(_Hoverfly).captureRequest(0xc820163290, 0x0, 0x55bd50, 0x0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:313 +0x12cf github.com/SpectoLabs/hoverfly/core.(_Hoverfly).processRequest(0xc820163290, 0xc820b0a2a0, 0xc820555ff8, 0x1) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:203 +0xb6 github.com/SpectoLabs/hoverfly/core.NewProxy.func2(0xc820b0a2a0, 0xc82094c370, 0xc82094c370, 0x1) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/proxy.go:51 +0x2a github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc8204f3fc0, 0xc820b0a2a0, 0xc82094c370, 0xc5001, 0xc820896d70) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x30 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ReqProxyConds).Do.func1(0xc820b0a2a0, 0xc82094c370, 0x26, 0x2f3501) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/dispatcher.go:200 +0x141 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc8200d0340, 0xc820b0a2a0, 0xc82094c370, 0x0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x30 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).filterRequest(0xc820019c00, 0xc820b0a2a0, 0xc82094c370, 0xc820b0a2a0, 0x0) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/proxy.go:56 +0xc7 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).handleHttps.func1(0x2cfc110, 0xc8206fa038, 0xc82038a780, 0xc82094c370, 0xc820a4c0e0, 0xc820019c00) /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:184 +0x891 created by github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(_ProxyHttpServer).handleHttps /home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:236 +0xe7a
Hey @subodhbrahmi,
I'm really sorry to hear that its becoming unusable. We are dedicated to working with you and trying to resolve this issue. We appreciate the updates from you.
We are still unable to recreate the issue between any of us at SpectoLabs. I have a few questions regarding the latest error though.
1 . Would you say that this error was triggered by the same actions as previous errors or is this new? 2. I notice that logs suggest that middleware is being run, would we be able to see a copy of this middleware?
If you would prefer to contact us directly, please feel free to email us at [email protected].
Closing issue as @daniel-bryant-uk and @benjih have tried to reproduce the problem and been unable to do so. If @subodhbrahmi provides further diagnostics we can reopen.
Opening ticket #275 as we should review what diagnostics Hoverfly supplies in such circumstances.
Can we re-open this please?
OS: Mac 10.11.6 Hoverly version: v0.9.1
Command sequence:
hoverctl start && hoverctl mode capture
Log:
{"level":"info","msg":"Creating in memory map backend...","time":"2016-11-28T10:54:00-06:00"} {"level":"warning","msg":"Turning off authentication...","time":"2016-11-28T10:54:00-06:00"} {"level":"info","msg":"Checking if keys in cache need rehashing","time":"2016-11-28T10:54:00-06:00"} {"Destination":".","Mode":"simulate","ProxyPort":"8500","level":"info","msg":"Proxy prepared...","time":"2016-11-28T10:54:00-06:00"} {"destination":".","level":"info","mode":"simulate","msg":"current proxy configuration","port":"8500","time":"2016-11-28T10:54:00-06:00"} {"level":"info","msg":"serving proxy","time":"2016-11-28T10:54:00-06:00"} {"AdminPort":"8888","level":"info","msg":"Admin interface is starting...","time":"2016-11-28T10:54:00-06:00"} [negroni] listening on :8888 [negroni] Started GET /api/v2/hoverfly/mode [negroni] Completed 200 OK in 130.145µs [negroni] Started PUT /api/v2/hoverfly/mode [negroni] Completed 200 OK in 106.954µs
curl --proxy http://localhost:8500 http://www.google.com
ERROR: curl: (52) Empty reply from server
Log:
{"error":"Get http://www.google.com/: dial tcp 216.58.218.100:80: getsockopt: connection refused","host":"www.google.com","level":"error","method":"GET","mode":"capture","msg":"could not forward request, failed to do an HTTP request.","path":"/","time":"2016-11-28T10:58:29-06:00"} {"error":"Get http://www.google.com/: dial tcp 216.58.218.100:80: getsockopt: connection refused","level":"error","mode":"capture","msg":"Got error when reading body after being modified by middleware","time":"2016-11-28T10:58:29-06:00"} 2016/11/28 10:58:29 http: panic serving [::1]:55105: runtime error: invalid memory address or nil pointer dereference goroutine 18 [running]: net/http.(*conn).serve.func1(0xc420156080) /usr/local/Cellar/go/1.7.3/libexec/src/net/http/server.go:1491 +0x12a panic(0x3c8d40, 0xc4200120c0) /usr/local/Cellar/go/1.7.3/libexec/src/runtime/panic.go:458 +0x243 github.com/SpectoLabs/hoverfly/core.(*Hoverfly).captureRequest(0xc4200a78c0, 0x0, 0x437202, 0x7, 0x1) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:266 +0x46a github.com/SpectoLabs/hoverfly/core.(*Hoverfly).processRequest(0xc4200a78c0, 0xc420178000, 0x20) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:165 +0xc87 github.com/SpectoLabs/hoverfly/core.NewProxy.func2(0xc420178000, 0xc420153a90, 0xc420153a90, 0xc42013e101) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/proxy.go:53 +0x34 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc4201346f0, 0xc420178000, 0xc420153a90, 0x1, 0x10) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x3a github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ReqProxyConds).Do.func1(0xc420178000, 0xc420153a90, 0xc42003db30, 0x161a5) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/dispatcher.go:200 +0xd2 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc420133c60, 0xc420178000, 0xc420153a90, 0xc42003db58, 0x122db) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x3a github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ProxyHttpServer).filterRequest(0xc42008c980, 0xc420178000, 0xc420153a90, 0xc42003dca0, 0x4) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/proxy.go:56 +0x70 github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ProxyHttpServer).ServeHTTP(0xc42008c980, 0x73bfc0, 0xc42015e0d0, 0xc420178000) /private/tmp/hoverfly-20161128-68480-qv752t/hoverfly-0.9.1/gopath/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/proxy.go:108 +0x2d9 net/http.serverHandler.ServeHTTP(0xc42008ca00, 0x73bfc0, 0xc42015e0d0, 0xc420178000) /usr/local/Cellar/go/1.7.3/libexec/src/net/http/server.go:2202 +0x7d net/http.(*conn).serve(0xc420156080, 0x73c740, 0xc42013a200) /usr/local/Cellar/go/1.7.3/libexec/src/net/http/server.go:1579 +0x4b7 created by net/http.(*Server).Serve /usr/local/Cellar/go/1.7.3/libexec/src/net/http/server.go:2293 +0x44d
Hey @sahas-,
No worries about reopening the issue.
I've just tried to do the same as you, with the newest release I get no problems.
The response from the curl request is
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/?gfe_rd=cr&ei=_2Q8WO22EcjW8gex05fQDQ">here</A>.
</BODY></HTML>
and my logs from Hoverfly
{"level":"info","msg":"Creating in memory map backend...","time":"2016-11-28T17:09:31Z"}
{"level":"warning","msg":"Turning off authentication...","time":"2016-11-28T17:09:31Z"}
{"level":"info","msg":"Checking if keys in cache need rehashing","time":"2016-11-28T17:09:31Z"}
{"Destination":".","Mode":"simulate","ProxyPort":"8500","level":"info","msg":"Proxy prepared...","time":"2016-11-28T17:09:31Z"}
{"destination":".","level":"info","mode":"simulate","msg":"current proxy configuration","port":"8500","time":"2016-11-28T17:09:31Z"}
{"level":"info","msg":"serving proxy","time":"2016-11-28T17:09:31Z"}
{"AdminPort":"8888","level":"info","msg":"Admin interface is starting...","time":"2016-11-28T17:09:31Z"}
[negroni] listening on :8888
[negroni] Started GET /api/v2/hoverfly/mode
[negroni] Completed 200 OK in 210.347µs
[negroni] Started GET /api/records
[negroni] Completed 200 OK in 3.930351ms
[negroni] Started GET /favicon.ico
[negroni] Completed 404 Not Found in 403.225µs
[negroni] Started PUT /api/v2/hoverfly/mode
[negroni] Completed 200 OK in 140.76µs
{"destination":"www.google.com","level":"info","method":"GET","middleware":"","mode":"capture","msg":"request and response captured","path":"/","rawQuery":"","time":"2016-11-28T17:10:23Z"}
To be sure its not a problem with certificates and keys, could you run that same curl command but ignore the TLS?
url --proxy http://localhost:8500 http://www.google.com --insecure
Same result..

I'm behind a corp proxy, can curl http://www.google.com without any issues.. Does Hoverly need any special setup behind proxy?
There shouldn't need to be any special setup that we know of.
If you are running behind another proxy, could you conduct the same tests but this time capture a local resource? Maybe run up a server on localhost and then try and curl to that via Hoverfly?
It seems to be something on the corp n/w and/or corp pc. It does work as expected for local service. I'll update here as I learn more on the corp n/w issue.
Hey!
First, thanks for the great project! Hoverfly is just what I need when developing crawlers :D
Now..I'm trying to use hoverfly to crawl a HTTPS site and having exactly the same problem reported here. Here is the log:
{"error":"Get https://cagr.sistemas.ufsc.br:443/modules/comunidade/cadastroTurmas/: dial tcp: lookup cagr.sistemas.ufsc.br on 127.0.1.1:53: dial udp 127.0.1.1:53: i/o timeout","host":"cagr.sistemas.ufsc.br","level":"error","method":"GET","mode":"capture","msg":"could not forward request, failed to do an HTTP request.","path":"/modules/comunidade/cadastroTurmas/","time":"2017-01-02T11:58:41-02:00"}
{"error":"Get https://cagr.sistemas.ufsc.br:443/modules/comunidade/cadastroTurmas/: dial tcp: lookup cagr.sistemas.ufsc.br on 127.0.1.1:53: dial udp 127.0.1.1:53: i/o timeout","level":"error","mode":"capture","msg":"Got error when reading body after being modified by middleware","time":"2017-01-02T11:58:41-02:00"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x4cefaa]
goroutine 8 [running]:
panic(0x7cfaa0, 0xc420012100)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/SpectoLabs/hoverfly/core.(*Hoverfly).captureRequest(0xc420146160, 0x0, 0x83e1b3, 0x7, 0x1)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:266 +0x46a
github.com/SpectoLabs/hoverfly/core.(*Hoverfly).processRequest(0xc420146160, 0xc4200ced20, 0x0)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/hoverfly.go:165 +0xc87
github.com/SpectoLabs/hoverfly/core.NewProxy.func2(0xc4200ced20, 0xc42018def0, 0xc42018def0, 0x1)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/proxy.go:53 +0x34
github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc42012ae90, 0xc4200ced20, 0xc42018def0, 0xc42019b201, 0x0)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x3a
github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ReqProxyConds).Do.func1(0xc4200ced20, 0xc42018def0, 0xc420306600, 0x0)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/dispatcher.go:200 +0xd2
github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.FuncReqHandler.Handle(0xc42013ec00, 0xc4200ced20, 0xc42018def0, 0xc420306600, 0x0)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/actions.go:19 +0x3a
github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ProxyHttpServer).filterRequest(0xc420086c80, 0xc4200ced20, 0xc42018def0, 0x0, 0x0)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/proxy.go:56 +0x70
github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ProxyHttpServer).handleHttps.func1(0xb44920, 0xc42002e3d0, 0xc420019e40, 0xc42018def0, 0xc4200ce780, 0xc420086c80)
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:184 +0x3dc
created by github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy.(*ProxyHttpServer).handleHttps
/home/ubuntu/.go_workspace/src/github.com/SpectoLabs/hoverfly/core/vendor/github.com/rusenask/goproxy/https.go:236 +0x107f
As I know Go, I studied the problem reported by the panic and found that the method that causes the panic returns a (*http.Response, error). But, where the second log happens in that method, there is no return after logging the error, so Go executes an ioutil.ReadAll(req.Body) after the if and..well, if doRequest returns an error, it returns req as nil, so req.Body causes a panic to happens.
Well, I do not knows too much about the internals of hoverfly, but that behavior seems a bit strange for me. The function captureRequest shouldn't have a return nil, err in each if err != nil { ... } block? I think this way the bug may be fixed correctly.
What you think? I hope to help find the cause of the panic, because with this panic hoverfly suddently stops and so my crawler, which is annoying. If that fix seems good to you, I will happily send a PR. :)
By the way..Sorry for my bad english. =)
hi, I saw that too and sent a message to @benjih about those errors last week. I am sure he will create a fix for that since you only need to return errors there. https://github.com/SpectoLabs/hoverfly/blob/master/core/hoverfly.go#L242-L265
Nice to know, @rusenask!
Thinking here, another solution is to simply rename req.Body and req before hf.doRequest(req) to another variables so we can avoid duplicated calls to ioutil.ReadAll.
Keep the good work resolving that bug. :)
Thanks for your help @fjorgemota . It is much appreciated. Your English is great. It's far better than my Portuguese!
If you want to raise a PR see Contributions in the readme.