I am trying to run this piece of code:-
[using version : 2.2.6]
var ngrok = require('ngrok');
ngrok.connect(function (err, url) {
console.log('err is ' + err);
console.log('url is ' + url);
});
Here is how the log looks like:-
err is Error: panic: runtime error: invalid memory address or nil pointer dereference
github.com/inconshreveable/olive/recover.go:40
runtime/asm_amd64.s:480
reflect/value.go:434
reflect/value.go:302
github.com/codegangsta/inject/inject.go:102
<autogenerated>:30
<autogenerated>:132
github.com/inconshreveable/olive/recover.go:29
runtime/asm_amd64.s:479
runtime/panic.go:458
github.com/inconshreveable/olive/error.go:37
runtime/asm_amd64.s:479
runtime/panic.go:458
runtime/panic.go:62
runtime/sigpanic_unix.go:24
lib/tunnel/client/reconnecting.go:39
lib/tunnel/client/session.go:97
ngrok/tunnel_session.go:138
ngrok/web_api.go:95
runtime/asm_amd64.s:480
reflect/value.go:434
reflect/value.go:302
github.com/codegangsta/inject/inject.go:102
<autogenerated>:30
github.com/go-martini/martini/router.go:373
github.com/go-martini/martini/router.go:367
github.com/inconshreveable/olive/error.go:41
runtime/asm_amd64.s:480
reflect/value.go:434
reflect/value.go:302
github.com/codegangsta/inject/inject.go:102
<autogenerated>:30
github.com/go-martini/martini/router.go:373
github.com/go-martini/martini/router.go:367
github.com/inconshreveable/olive/recover.go:32
runtime/asm_amd64.s:480
reflect/value.go:434
reflect/value.go:302
github.com/codegangsta/inject/inject.go:102
<autogenerated>:30
github.com/go-martini/martini/router.go:373
github.com/go-martini/martini/router.go:367
github.com/inconshreveable/olive/logger.go:17
runtime/asm_amd64.s:480
reflect/value.go:434
reflect/value.go:302
github.com/codegangsta/inject/inject.go:102
<autogenerated>:30
github.com/go-martini/martini/router.go:373
github.com/go-martini/martini/router.go:250
github.com/go-martini/martini/router.go:120
ngrok/src/ngrok/web.go:27
runtime/asm_amd64.s:480
reflect/value.go:434
reflect/value.go:302
github.com/codegangsta/inject/inject.go:102
github.com/go-martini/martini/martini.go:173
github.com/go-martini/martini/martini.go:69
I get this as well on 2.2.4 on Windows when trying to POST to the http://localhost:4040/api/tunnels endpoint with a JSON request to create a new tunnel:
{
"name": "WebApplication4",
"addr": "localhost:46368",
"proto": "http",
"subdomain": "dpro",
"host_header": "localhost:46368"
}
If I wait 1 second and retry, it works. Only seems to happen right after I start the ngrok process. Some kind of race condition.
Ran into this while trying to automate some tests with ngrok version 2.2.8 (Mac). The ngrok API will respond successfully to GET requests before it is ready to create new tunnels.
Here's a reproducible test case (using just curl to avoid any potential concerns about ngrok client libraries):
#!/bin/bash
ngrok version
killall ngrok 2> /dev/null # start clean
echo 'Starting ngrok in background'
ngrok start --none > ngrok.log &
echo -n 'Waiting for API: '
until curl 'http://127.0.0.1:4040/api/tunnels' -s -o /dev/null; do
echo -n '. '
done
echo 'responding successfully'
echo
echo 'Trying to create tunnel:' # this will panic
curl -i 'http://127.0.0.1:4040/api/tunnels' \
-H 'Content-Type: application/json' \
-d '{"name":"test", "proto":"http", "addr":"8000"}'
echo
echo 'Waiting a bit longer, then trying again:' # this will work
sleep 1
curl -i 'http://127.0.0.1:4040/api/tunnels' \
-H 'Content-Type: application/json' \
-d '{"name":"test", "proto":"http", "addr":"8000"}'
kill $! # quit the background ngrok
Result:
ngrok version 2.2.8
Starting ngrok in background
Waiting for API: . . responding successfully
Trying to create tunnel:
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Tue, 10 Apr 2018 20:40:11 GMT
Content-Length: 1890
panic: runtime error: invalid memory address or nil pointer dereference
github.com/inconshreveable/olive/recover.go:40
runtime/asm_amd64.s:515
reflect/value.go:434
# ... snip ...
github.com/go-martini/martini/martini.go:173
github.com/go-martini/martini/martini.go:69
Waiting a bit longer, then trying again:
HTTP/1.1 201 Created
Content-Type: application/json
Date: Tue, 10 Apr 2018 20:40:13 GMT
Content-Length: 336
{"name":"test","uri":"/api/tunnels/test","public_url":"https://c3c2795f.ngrok.io", # ...
I was getting this error when trying to open an ngrok tunnel through Visual Studio. Fixed by running as administrator.
May not be applicable to this use case but may help some onlookers.
Get similar error when running ngrok in Bot Framework Emulator
Running the emulator as admin does not solve it.
Failed to spawn ngrok
panic:
runtime error: invalid memory address or nil pointer dereference
github.com/inconshreveable/[email protected]/recover.go:40
reflect/value.go:447
reflect/value.go:308
github.com/codegangsta/[email protected]/inject.go:102
github.com/inconshreveable/[email protected]/recover.go:29
runtime/panic.go:522
github.com/inconshreveable/[email protected]/error.go:37
runtime/panic.go:522
runtime/panic.go:82
runtime/signal_windows.go:233
go/lib/tunnel/client/reconnecting.go:25
go/lib/tunnel/client/session.go:94
go/cmd/ngrok/tunnels/session.go:138
go/cmd/ngrok/tunnels/tunnels.go:44
go/cmd/ngrok/web/api.go:93
reflect/value.go:447
reflect/value.go:308
github.com/codegangsta/[email protected]/inject.go:102
github.com/go-martini/[email protected]/router.go:373
github.com/go-martini/[email protected]/router.go:367
github.com/inconshreveable/[email protected]/error.go:41
reflect/value.go:447
reflect/value.go:308
github.com/codegangsta/[email protected]/inject.go:102
github.com/go-martini/[email protected]/router.go:373
github.com/go-martini/[email protected]/router.go:367
github.com/inconshreveable/[email protected]/recover.go:32
reflect/value.go:447
reflect/value.go:308
github.com/codegangsta/[email protected]/inject.go:102
github.com/go-martini/[email protected]/router.go:373
github.com/go-martini/[email protected]/router.go:367
github.com/inconshreveable/[email protected]/logger.go:17
reflect/value.go:447
reflect/value.go:308
github.com/codegangsta/[email protected]/inject.go:102
github.com/go-martini/[email protected]/router.go:373
github.com/go-martini/[email protected]/router.go:250
github.com/go-martini/[email protected]/router.go:120
reflect/value.go:447
reflect/value.go:308
github.com/codegangsta/[email protected]/inject.go:102
github.com/go-martini/[email protected]/martini.go:173
github.com/go-martini/[email protected]/martini.go:69
Most helpful comment
I was getting this error when trying to open an ngrok tunnel through Visual Studio. Fixed by running as administrator.
May not be applicable to this use case but may help some onlookers.