# \[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6d8962\]

**URL:** <https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438>\
**Category:** Go Client\
**Created:** [August 9, 2018, 1:21pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438 "2018-08-09T13:21:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 9, 2018, 1:21pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/1 "2018-08-09T13:21:48Z")

</div>

I have got this error twice and speaking frankly, I am “segmentation violation hater”

Error is :-

```auto
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6d8962]

goroutine 1 [running]:
github.com/aerospike/aerospike-client-go.(*Client).Close(0x0)
        /home/krokite/go/src/github.com/aerospike/aerospike-client-go/client.go:111 +0x22

```

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 9, 2018, 1:43pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/2 "2018-08-09T13:43:05Z")

</div>

Would you paste the rest of the stack trace?

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 9, 2018, 2:04pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/3 "2018-08-09T14:04:14Z")

</div>

That is the only log, I can see in terminal, when I forcefully closed my go app.

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 10, 2018, 11:24am UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/4 "2018-08-10T11:24:45Z")

</div>

It looks like the `client` object you are calling `Close()` on is `nil`!

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 10, 2018, 12:24pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/5 "2018-08-10T12:24:49Z")

</div>

This is what I have done.

```auto
client, err := as.NewClient("127.0.0.1", 3000)
	check(err)
	defer client.Close()

```

I am really not sure, what went wrong, should I also call function where if app is closed on interrupt should close the connection then?

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 10, 2018, 12:40pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/6 "2018-08-10T12:40:43Z")

</div>

As I suspected 🙂

If there’s an error, the `client` object will be `nil`. You are trying to call a method on a nil pointer.

This is how you should do it:

```nohighlight
client, err := as.NewClient("127.0.0.1", 3000)
if err != nil {
    // handle error here
    // probably log and exit the app, or maybe retry
}

// we now know there was no error; so we can use our pointer
defer client.Close()

```

I strongly recommend reading a bit more about Go from the [golang.org](http://golang.org) before continuing your app. That’s a couple of days of time well spent, and learning the idiomatic way of writing Go programs will pay off in the long run.

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 10, 2018, 12:48pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/7 "2018-08-10T12:48:47Z")

</div>

Hi, I think, I missed to provide other part.

```auto
check(err) // This is my custom function for checking error

func check(err error) {
    if err != nil {
        fmt.println("Error: "+err.Error())
        panic("gone")
    }
}

```

That’s how it is handled when i mentioned

```auto
client, err := as.NewClient("127.0.0.1", 3000)
check(err) // <- here
defer client.Close()

```

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 10, 2018, 1:00pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/8 "2018-08-10T13:00:28Z")

</div>

then add a nil check around the defer line and see what’s coming in. Are you gettng both a nil error and a nil client?

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 10, 2018, 1:05pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/9 "2018-08-10T13:05:28Z")

</div>

I just added another close when Interrupted -

```auto
client, err := as.NewClient("127.0.0.1", 3000)

// this function will run when program is exited on press of ctrl-c/cmd-c
app.RegisterOnInterrupt(func() {
    // check if client is connected
	if client.IsConnected() {
		client.Close()
	}
})

defer client.Close()

```

Let me know, if I can use `client.IsConnected()` function to check and than close on true.?

---

<div class="post-metadata">

**Author:** ![khosrow](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/khosrow/32/49_2.png) [@khosrow](https://discuss.aerospike.com/u/khosrow)\
**Post date:** [August 10, 2018, 1:38pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/10 "2018-08-10T13:38:46Z")

</div>

The problem you are encountering is that your `client` object is `nil`.

Multiple close calls to a client should not cause any problem.

You have to find out _if_ and _why_ that client object is `nil` when there is no error on connect.

---

<div class="post-metadata">

**Author:** ![rocky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rocky/32/1026_2.png) [@rocky](https://discuss.aerospike.com/u/rocky)\
**Post date:** [August 10, 2018, 1:49pm UTC](https://discuss.aerospike.com/t/signal-sigsegv-segmentation-violation-code-0x1-addr-0x0-pc-0x6d8962/5438/11 "2018-08-10T13:49:44Z")

</div>

how can I find the real culprit, if client is nil, if err would have been nil on first case, it would have immediately thrown an error, but this error comes sometimes when I close the app using `ctrl-c` in my ubuntu.
