Open SoMuchForSubtlety opened 5 years ago
Iirc there was some race condition with wanting to access the list of connected users before the NAMES message was fully parsed or something along these lines... Try go build -race
etc. and you should find it.
yea it seems to be a race, I think I cause it by closing the connection very quickly after opening it.
this is the output when I just open the connection and immediately close it. I get this very consistently
$ go run -race .\main.go
==================
WARNING: DATA RACE
Write at 0x00c000050470 by main goroutine:
github.com/MemeLabs/dggchat.(*Session).Close()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:138 +0x118
main.main()
C:/Users/jakob/Documents/projects/test/main.go:29 +0x486
Previous read at 0x00c000050470 by goroutine 13:
github.com/MemeLabs/dggchat.(*Session).listen()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:164 +0x63
Goroutine 13 (running) created at:
github.com/MemeLabs/dggchat.(*Session).open()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:115 +0x219
github.com/MemeLabs/dggchat.(*Session).Open()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:91 +0xe1
main.main()
C:/Users/jakob/Documents/projects/test/main.go:24 +0x426
==================
Found 1 data race(s)
exit status 66
this is the output when I open the connection, send one message and then close it. I only got this twice, otherwise it ran normally
==================
WARNING: DATA RACE
Read at 0x00c000050470 by goroutine 13:
github.com/MemeLabs/dggchat.(*Session).listen()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:164 +0x63
Previous write at 0x00c000050470 by main goroutine:
github.com/MemeLabs/dggchat.(*Session).Close()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:138 +0x118
main.main()
C:/Users/jakob/Documents/projects/test/main.go:36 +0x5ca
Goroutine 13 (running) created at:
github.com/MemeLabs/dggchat.(*Session).open()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:115 +0x219
github.com/MemeLabs/dggchat.(*Session).Open()
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:91 +0xe1
main.main()
C:/Users/jakob/Documents/projects/test/main.go:26 +0x426
==================
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x78fc8f]
goroutine 8 [running]:
github.com/gorilla/websocket.(*Conn).NextReader(0x0, 0xc000062b70, 0x46d09c, 0x401d80, 0x1913588, 0x0)
C:/Users/jakob/go/src/github.com/gorilla/websocket/conn.go:939 +0x4f
github.com/gorilla/websocket.(*Conn).ReadMessage(0x0, 0x6f, 0x2, 0xc0001640a0, 0x2, 0x4, 0x0)
C:/Users/jakob/go/src/github.com/gorilla/websocket/conn.go:1029 +0x58
github.com/MemeLabs/dggchat.(*Session).listen(0xc0000503c0)
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:164 +0x7c
created by github.com/MemeLabs/dggchat.(*Session).open
C:/Users/jakob/go/src/github.com/MemeLabs/dggchat/session.go:115 +0x21a
I sometimes get this when trying to connect. seems to happen randomly, I don't change anything.