resolve data race conditions, code quality

This commit is contained in:
David Zhao
2021-06-04 14:57:55 -07:00
parent 5baf97e99b
commit a3228c2ae9
17 changed files with 95 additions and 293 deletions
+4 -3
View File
@@ -307,10 +307,11 @@ func (r *RoomManager) getOrCreateRoom(roomName string) (*rtc.Room, error) {
if err := r.DeleteRoom(roomName); err != nil {
logger.Errorw("could not delete room", err)
}
// print stats
logger.Infow("room closed",
"incomingStats", room.GetIncomingStats(),
"outgoingStats", room.GetOutgoingStats(),
"incomingStats", room.GetIncomingStats().Copy(),
"outgoingStats", room.GetOutgoingStats().Copy(),
)
})
room.OnParticipantChanged(func(p types.Participant) {
@@ -336,7 +337,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
defer func() {
logger.Debugw("RTC session finishing",
"participant", participant.Identity(),
"room", room.Name,
"room", room.Room.Name,
)
_ = participant.Close()
}()
+2 -1
View File
@@ -177,7 +177,8 @@ func (s *LivekitServer) Start() error {
}
// wait for shutdown
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
_ = s.httpServer.Shutdown(ctx)
if s.turnServer != nil {
+1 -1
View File
@@ -1,6 +1,6 @@
// Code generated by Wire. DO NOT EDIT.
//go:generate go run github.com/google/wire/cmd/wire
//go:generate wire
//+build !wireinject
package service
+7 -2
View File
@@ -45,14 +45,18 @@ func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, error) {
msg := &livekit.SignalRequest{}
switch messageType {
case websocket.BinaryMessage:
c.mu.Lock()
// switch to protobuf if client supports it
c.useJSON = false
c.mu.Unlock()
// protobuf encoded
err := proto.Unmarshal(payload, msg)
return msg, err
case websocket.TextMessage:
c.mu.Lock()
// json encoded, also write back JSON
c.useJSON = true
c.mu.Unlock()
err := protojson.Unmarshal(payload, msg)
return msg, err
default:
@@ -67,6 +71,9 @@ func (c *WSSignalConnection) WriteResponse(msg *livekit.SignalResponse) error {
var payload []byte
var err error
c.mu.Lock()
defer c.mu.Unlock()
if c.useJSON {
msgType = websocket.TextMessage
payload, err = protojson.Marshal(msg)
@@ -78,8 +85,6 @@ func (c *WSSignalConnection) WriteResponse(msg *livekit.SignalResponse) error {
return err
}
c.mu.Lock()
defer c.mu.Unlock()
return c.conn.WriteMessage(msgType, payload)
}