knadh / niltalk

Instant, disposable, single-binary web based live chat server. Go + VueJS.
GNU Affero General Public License v3.0
952 stars 117 forks source link

A lot race issue? #11

Closed elsonwu closed 4 years ago

elsonwu commented 7 years ago

I found a lot possible race issues in this project.

For example, the Room struct, the run method goroutine read/write the room.peers, but out of the run method, there're also some other goroutine read the room.peers without lock, it might case race issue.

// Write in one goroutine

...
go rooms[id].run()
...

select {
    // A new peer has connected.
    case peer, ok := <-room.register:
        if ok {
            room.peers[peer] = true
    // ...

But out of the run method goroutine, there is another goroutine read it without lock.

// Read in another goroutine
func (room *Room) peerList() map[string]string {
    list := make(map[string]string)

    for peer := range room.peers {
        list[peer.id] = peer.handle
    }

    return list
}

I found some more places like this, it should case race issue.

knadh commented 4 years ago

Apologies. I know it's taken forever, but I've just published a complete rewrite of Niltalk. Please check the repo.