christos27 / goapp

GNU General Public License v3.0
0 stars 0 forks source link

#1 Session Stats are not updated #3

Closed christos27 closed 1 month ago

christos27 commented 1 month ago

The error happens because in Server.incStats() we get a copy of the sessionStats slice's sessionStats struct. We then modify this copy which does not affect the sessionStats struct residing in slice Server.sessionStats.

With this solution in Server.incStats() we will use index iterating in order to affect the slice's struct instead of its copy.

christos27 commented 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: problem-1-2