Handling error while connecting to kubernetes server using config file - go

I intentionally broke my .config file which is responsible for connecting to kubernetes server by changing the content in the user section and I am getting this error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x45756e]
goroutine 1 [running]:
k8s.io/client-go/kubernetes.NewForConfig(0x0, 0x0, 0xc42031c120, 0x1c)
/home/saivamsi/go/src/k8s.io/client-go/kubernetes/clientset.go:371 +0x4e
exit status 2
I was doing this to test what happens if somehow invalid config was supplied so I want to handle this error by retrying to connect to server for next 5sec to see if it. How can I achieve this?
I am using kubernetes go client with this code to make the connection:
var KubeConfigPath = os.Getenv("HOME") + "/.kube/config2"
var config, ConfigErr = clientcmd.BuildConfigFromFlags("", KubeConfigPath)
var clientset, ClientErr = kubernetes.NewForConfig(config)

You can likely avoid the segfault if you check that the error from BuildConfigFromFlags is not nil. If it is nil then sleep and retry, otherwise continue.

Related

Why am I getting ‘panic: runtime error: invalid memory address or nil pointer dereference’ accessing Firestore on new computer? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I get a Panic if I attempt to run the tests or runthe app directly via: go run main.go
The code works great on my old Macbook Pro. It panics on my new Macbook Pro.
I believe the error has Something to do with accessing the Firestore datastore but I'm not sure what's going wrong.
I'm running the same code so datastore Keys and everything else should be identical.
Here is the Github repo:
https://github.com/golangnewb/FirestoreTestHttp
Working Computer:
go version go1.11.2 darwin/amd64
Panic Computer:
go version go1.13.5 darwin/amd64
❯ go test
--- FAIL: TestCities (0.01s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x14d557a]
goroutine 6 [running]:
testing.tRunner.func1(0xc000312200)
/usr/local/go/src/testing/testing.go:874 +0x3a3
panic(0x15ac100, 0x1b3e740)
/usr/local/go/src/runtime/panic.go:679 +0x1b2
cloud.google.com/go/firestore.(*Client).path(...)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:107
cloud.google.com/go/firestore.(*Client).Collection(0x0, 0x1677ac0, 0x6, 0x14)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:122 +0x9a
_/Users/XXX/Dropbox/go/src/firestoreTestHttp.addCitiesFirestore(0x5e4c4feb, 0xc000064760)
/Users/XXX/Dropbox/go/src/firestoreTestHttp/city_handlers_test.go:218 +0x13d
_/Users/XXX/Dropbox/go/src/firestoreTestHttp.TestCities(0xc000312200)
/Users/XXX/Dropbox/go/src/firestoreTestHttp/city_handlers_test.go:19 +0x26
testing.tRunner(0xc000312200, 0x16a1c98)
/usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:960 +0x350
exit status 2
FAIL _/Users/XXX/Dropbox/go/src/firestoreTestHttp 0.165s
Here is the panic if I try to run via:
❯ go run main.go
2020/02/18 17:19:39 http: panic serving [::1]:60479: runtime error: invalid memory address or nil pointer dereference
goroutine 9 [running]:
net/http.(*conn).serve.func1(0xc00027c6e0)
/usr/local/go/src/net/http/server.go:1767 +0x139
panic(0x15a69c0, 0x1b39a50)
/usr/local/go/src/runtime/panic.go:679 +0x1b2
cloud.google.com/go/firestore.(*Client).path(...)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:107
cloud.google.com/go/firestore.(*Client).Collection(0x0, 0x16728ba, 0x6, 0x14)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:122 +0x9a
main.indexHandler(0x1744360, 0xc000322000, 0xc0002c8200)
/Users/XXX/Dropbox/go/src/firestoreTestHttp/main.go:50 +0xa2
net/http.HandlerFunc.ServeHTTP(0x169da80, 0x1744360, 0xc000322000, 0xc0002c8200)
/usr/local/go/src/net/http/server.go:2007 +0x44
net/http.(*ServeMux).ServeHTTP(0xc0002ea100, 0x1744360, 0xc000322000, 0xc0002c8200)
/usr/local/go/src/net/http/server.go:2387 +0x1bd
net/http.serverHandler.ServeHTTP(0xc000312000, 0x1744360, 0xc000322000, 0xc0002c8200)
/usr/local/go/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc00027c6e0, 0x17457a0, 0xc00008cf80)
/usr/local/go/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2928 +0x384
Although I dont feel well in Go I will try a shot. If I am wrong just let me know.
From the error it seems that Client is nil. In attached Git repo in main you are logging that it should be set as environment variable GCLOUD_PROJECT, however I haven't found any so.Getenv function that gets this value. Maybe this value is wrong...?
So I guess this statement client, _ := firestore.NewClient(ctx, projectID) is being called with wrong projectID. In the statement error handling is omitted, so we do not know if the client has been created properly. If it was not created, that we should get such error.
Maybe you should add error handling like in example in Go Firestore Reference, to ensure that there is no error during client creation.
I hope this will help you!

Using centos7 as base image for Jaeger

I am trying to setup Jaeger using a CentOS base image instead of Alpine. The agent, collector, and Cassandra containers all work fine except for the query container.
The Jaeger repository is here.
After changing the base image to CentOS 7, commenting out the sections that apply to copying ca-certificates.crt and running docker-compose, I get the following nil pointer error message when tailing the query container
panic: runtime error: invalid memory address or nil pointer dereference
I ran the makefile with the necessary flags to compile the code in the app directory.
Has anyone ever setup Jaeger using CentOS as a base image?
Below is the full stack error from the container
goroutine 1 [running]:
github.com/jaegertracing/jaeger/cmd/query/app.NewStaticAssetsHandler(0x0, 0x0, 0xe6cb85, 0x1, 0x0, 0x0, 0xc0000397a0, 0xc0000397b0, 0xc000137098)
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/cmd/query/app/static_handler.go:74 +0x5e
github.com/jaegertracing/jaeger/cmd/query/app.RegisterStaticHandler(0xc0000a7bd0, 0xc00009d080, 0xc0001eec80)
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/cmd/query/app/static_handler.go:45 +0x74
main.main.func1(0xc0001746c0, 0xc000184f60, 0x0, 0x2, 0x0, 0x0)
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/cmd/query/main.go:131 +0x14eb
github.com/jaegertracing/jaeger/vendor/github.com/spf13/cobra.(*Command).execute(0xc0001746c0, 0xc00008e0a0, 0x2, 0x2, 0xc0001746c0, 0xc00008e0a0)
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/vendor/github.com/spf13/cobra/command.go:698 +0x47a
github.com/jaegertracing/jaeger/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc0001746c0, 0x0, 0x4, 0xc00009cfc0)
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/vendor/github.com/spf13/cobra/command.go:783 +0x2dc
github.com/jaegertracing/jaeger/vendor/github.com/spf13/cobra.(*Command).Execute(0xc0001746c0, 0xc0001746c0, 0xc000137f28)
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/vendor/github.com/spf13/cobra/command.go:736 +0x2b
main.main()
/Users/myusername/Go/src/github.com/jaegertracing/jaeger/cmd/query/main.go:172 +0x5a6
{"level":"info","ts":1539888666.5870771,"caller":"healthcheck/handler.go:99","msg":"Health Check server started","http-port":16687,"status":"unavailable"}
{"level":"info","ts":1539888666.6052766,"caller":"cassandra/factory.go:92","msg":"Cassandra archive storage configuration is empty, skipping"}
{"level":"info","ts":1539888666.6063912,"caller":"query/main.go:186","msg":"Archive storage not created","reason":"Archive storage not configured"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xbe2b9e
This is most likely caused by the static assets not being included in the binary. You can try that out by running the binary you compiled.
Instead of compiling on your own, a better approach would be to get the official binaries from the releases page and build your Docker container using that.
https://github.com/jaegertracing/jaeger/releases/latest

Kapacitor record stream with influxdb connection probleme

I'am trying to record a stream task in kapacitor & Influxdb.
I Use Windows 7 Entreprise, I've installed telegraf (to collect data) & influxdb and they both work (tested with grafana dashboard), but when i start Kapacitor and try to record a task, i get this error "wsarecv : An existing connection was forcibly closed by the remote host" (And Kapacitor server Stop).
And I get this error on Kapacitor Server Cmd :
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x48 pc=0x5ada1d]
goroutine 46 [running]:
panic(0x1d23000, 0xc04200e070)
/usr/local/go/src/runtime/panic.go:500 +0x1af
github.com/influxdata/kapacitor/services/replay.(*Service).doRecordStream(0xc042
17d290, 0xc042ac5bc0, 0x24, 0x0, 0x0, 0xed1baf5dd, 0xc0079d8620, 0x2ed2e20, 0xc0
42679000, 0x1, ...)
/root/go/src/github.com/influxdata/kapacitor/services/replay/service.go:
1256 +0x11d
github.com/influxdata/kapacitor/services/replay.(*Service).handleRecordStream.fu
nc1(0xc04202a680, 0xc04217d290, 0xc0425308c0, 0xc042531680, 0xc042ac5bc0, 0x24,
0xc04220e7e0, 0x62, 0x0, 0x0, ...)
/root/go/src/github.com/influxdata/kapacitor/services/replay/service.go:
622 +0x12c
created by github.com/influxdata/kapacitor/services/replay.(*Service).handleReco
rdStream
/root/go/src/github.com/influxdata/kapacitor/services/replay/service.go:
624 +0x4f0
c:\InfluxDb\kapacitor>
Anyone got an idea on how to resolve this ?
This bug has been fixed in the latest release 1.4.0. See for the specific fix https://github.com/influxdata/kapacitor/pull/15422
The 1.4.0 release contains that fix. Version 1.4.0 was released 3 days ago and the downloads page should be updated soon.

Parse deploy command error x509

On parse deploy command I get this error, how can I solve it?
x509: failed to load system roots and no roots provided.
/home/travis/gopath/src/github.com/ParsePlatform/parse-cli/main.go:143 checkIfSupported
/home/travis/gopath/src/github.com/ParsePlatform/parse-cli/main.go:101 main
/home/travis/.gimme/versions/go1.4.2.linux.amd64/src/runtime/proc.go:72 main
/home/travis/.gimme/versions/go1.4.2.linux.amd64/src/runtime/asm_386.s:2288 goexit
(OS Ubuntu 14.04 LTS 64)
UPDATE
Now sometimes, one in ten attempts, it requests email and password. But, after input password, I get:
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x1 pc=0x8097025]
I solved executing an update-ca-certificates command. I think that certificates were broken and it stopped to work, but I dont know why.

golang: runtime error: invalid memory address or nil pointer dereference

I am new to golang and currently following this tutorial and source code here - http://golang.org/doc/articles/wiki/part2.go
After building this file, I am getting
calvin$ ./mywebwiki2
2012/07/23 17:12:59 http: panic serving [::1]:58820: runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/pkg/net/http/server.go:576 (0x3f202)
_func_003: buf.Write(debug.Stack())
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:1443 (0x10c79)
/private/tmp/bindist454984655/go/src/pkg/runtime/runtime.c:128 (0x11745)
/private/tmp/bindist454984655/go/src/pkg/runtime/thread_darwin.c:418 (0x148b5)
/Users/calvin/work/gowiki/mywebwiki2.go:33 (0x2248)
viewHandler: fmt.Fprintf(w, "<h1>%s</h1><div>%s</div>", p.Title, p.Body)
/usr/local/go/src/pkg/net/http/server.go:690 (0x331ae)
HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:926 (0x34030)
(*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:656 (0x32fc1)
(*conn).serve: handler.ServeHTTP(w, w.req)
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:271 (0xed7f)
2012/07/23 17:12:59 http: panic serving [::1]:58821: runtime error: invalid memory address or nil pointer dereference
Any idea what I did wrong to be causing this apparent memory corruption?
There's an ignored err at line 36. The error probably says open .txt: no such file or directory if you tested in browser using URL http://localhost:8080/view/ or open foo.txt: no such file or directory if you tested in browser using URL http://localhost:8080/view/foo. In the later case there must be a file "foo.txt" in your working directory for this example code to work. After that the code seems to work for me locally.
Someone should probably fill an issue about the ignored error value.
In the tutorial, you created the file TestPage previously. Which is the page you should be navigating to when you first build the server. In the tutorial, they have you navigate to view/test instead of view/TestPage as you should which is what creates the confusion.

Resources