commit 968953f237fe2ceaee9bdc8949d29feb5a93715f
parent 8af4a8d1db4aca36417d33e2020d069db02330c1
Author: Vetle Haflan <vetle@haflan.dev>
Date: Fri, 29 Jan 2021 00:21:07 +0100
Nvm, I just got rid of the error message with a deadlock
ReadJSON blocks while it waits for a message, making the entire room
deadlock if we lock it. Remember: *Don't lock a blocking code block.*
Better solution: Add the error code as an expectedCode instead.
Diffstat:
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lipre.go b/lipre.go
@@ -68,14 +68,13 @@ func (room *Room) Close(presenter bool) {
func (room *Room) listen() {
for {
- room.mu.Lock()
var file File
err := room.presenter.ReadJSON(&file)
if err != nil {
- if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
- log.Printf("Connection to room '%v' closed by presenter", room.code)
+ if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure, websocket.CloseAbnormalClosure) {
+ log.Printf("Unexpected close error: %v", err)
} else {
- log.Printf("error: %v", err)
+ log.Printf("Connection to room '%v' closed by presenter", room.code)
}
// TODO: Handle JSON errors (send info to presenter)
return
@@ -87,7 +86,6 @@ func (room *Room) listen() {
}
viewerConn.WriteJSON(&file)
}
- room.mu.Unlock()
}
}