Closed christos27 closed 1 month ago
Logs: 2024/09/07 13:54:47 server.go:30: GoApp Started 127.0.0.1 - - [07/Sep/2024:13:55:09 +0300] "GET /goapp HTTP/1.1" 200 1928 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0" 2024/09/07 13:55:12 handler_websocket.go:40: websocket started for watcher 52659656-99f6-49a0-b328-acdd03f2d69f 2024/09/07 13:55:16 handler_websocket.go:42: websocket stopped for watcher 52659656-99f6-49a0-b328-acdd03f2d69f 2024/09/07 13:55:16 stats.go:11: session 52659656-99f6-49a0-b328-acdd03f2d69f has received 4 messages 127.0.0.1 - - [07/Sep/2024:13:55:12 +0300] "GET /goapp/ws HTTP/1.1" 200 0 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0"
Screenshots:
The error happens because in
Server.incStats()
we get a copy of thesessionStats
slice'ssessionStats
struct. We then modify this copy which does not affect thesessionStats
struct residing in sliceServer.sessionStats
.With this solution in
Server.incStats()
we will use index iterating in order to affect the slice's struct instead of its copy.