Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent issue on CatapultClient.Listen() when closing websocket #39

Open
avanaur opened this issue Jun 12, 2019 · 0 comments
Open

Comments

@avanaur
Copy link

avanaur commented Jun 12, 2019

Listen() seems to spawn a goroutine for reading websocket messages.

However, when the websocket is closed, the goroutine sometimes fails with this panic error.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc8 pc=0xa44116]

goroutine 2753 [running]:
github.com/gorilla/websocket.(*Conn).NextReader(0x0, 0xc00000ed28, 0xc000419f40, 0x404de5, 0xc00053e420, 0xc000419f90)
        C:/Users/Tyrone/go/src/github.com/gorilla/websocket/conn.go:936 +0x26
github.com/gorilla/websocket.(*Conn).ReadMessage(0x0, 0xc000419f90, 0xc0003cac00, 0x331, 0x600, 0x0, 0x0)
        C:/Users/Tyrone/go/src/github.com/gorilla/websocket/conn.go:1026 +0x2f
github.com/proximax-storage/go-xpx-catapult-sdk/sdk/websocket.(*CatapultWebsocketClientImpl).Listen.func1(0xc000375900, 0xc00053e420)
        C:/Users/Tyrone/go/src/github.com/proximax-storage/go-xpx-catapult-sdk/sdk/websocket/client.go:132 +0x116
created by github.com/proximax-storage/go-xpx-catapult-sdk/sdk/websocket.(*CatapultWebsocketClientImpl).Listen
        C:/Users/Tyrone/go/src/github.com/proximax-storage/go-xpx-catapult-sdk/sdk/websocket/client.go:127 +0x98

My understanding is due to the setting of conn to nil as shown on the line below.

	for {
		select {
		case <-c.ctx.Done():
			if c.conn != nil {
				if err := c.conn.Close(); err != nil {
					panic(err)
				}
				c.conn = nil
			}
			return
		case msg := <-messagesChan:
			go c.messageRouter.RouteMessage(msg)
		}
	}

Can we remove the c.conn = nil to avoid panic?

For some reason, I can't replicate on a simple code the issue but on the app it always happens. The removal of above fixed my proble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant