Browse Source

Prevent data race when getting room type that was set through NATS.

pull/413/head
Joachim Bauch 9 years ago
parent
commit
e3dda72af8
Failed to extract signature
  1. 9
      go/channelling/room_manager.go

9
go/channelling/room_manager.go

@ -109,6 +109,9 @@ func (rooms *roomManager) setNatsRoomType(msg *roomTypeMessage) { @@ -109,6 +109,9 @@ func (rooms *roomManager) setNatsRoomType(msg *roomTypeMessage) {
return
}
// TODO(fancycode): Should we use a separate mutex for this?
rooms.Lock()
defer rooms.Unlock()
if msg.Type != "" {
log.Printf("Setting room type for %s to %s\n", msg.Path, msg.Type)
rooms.roomTypes[msg.Path] = msg.Type
@ -274,7 +277,11 @@ func (rooms *roomManager) MakeRoomID(roomName, roomType string) string { @@ -274,7 +277,11 @@ func (rooms *roomManager) MakeRoomID(roomName, roomType string) string {
}
func (rooms *roomManager) getConfiguredRoomType(roomName string) string {
if roomType, found := rooms.roomTypes[roomName]; found {
// TODO(fancycode): Should we use a separate mutex for this?
rooms.RLock()
roomType, found := rooms.roomTypes[roomName]
rooms.RUnlock()
if found {
// Type of this room was overwritten through NATS.
return roomType
}

Loading…
Cancel
Save