-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unused AddRune method. The AddRune method was used for local insertions to update the editor's slice of runes, bypassing the CRDT doc entirely. The editor's slice of runes was then being immediately overwritten by a CRDT insert, so AddRune was doing nothing. This removes the AddRune method and slightly adapts the local insertion logic to keep behavior the same. * Add mutex around local clock increment. The GenerateInsert method increments the local clock. Without a mutex, a race condition was possible because both the local and message handling threads were able to insert characters simultaneously. * Make status bar show active users. Status bar now shows all active users connected to the server. * Add cell to status bar showing connection status. * Add mutex to avoid concurrent read/write panics. The Gorilla WebSocket package does not support concurrent reads and writes. The server would occasionally panic on a concurrent write, so I followed the recommendation at (https://github.com/gorilla/websocket/ issues/119#issuecomment-198710015) to use a mutex. Also changed the name of the `clientInfo` type to `client` to better reflect its purpose. * Refactor status bar logic. Status messages are now sent on a buffered channel, to allow for multiple threads to update the status without conflict. There's a separate status message handler that asynchronously listens on the channel and temporarily shows any received messages. Usernames in the status bar are now rendered in different colors. * Fix linter and DeepSource issues. * Fix miscellaneous issues. Changed string concatenation to use fmt.Sprintf() instead of '+'. Fixed potential out-of-bounds error with the userColors slice. * Refactor to fix concurrency bugs and data races. Previously, there were data races occurring due to multiple goroutines concurrently reading from and writing to the `activeClients` map. The main change is that there is now a monitor goroutine method called `handle` that ensures that all modifications to the list of active clients happen sequentially. Any other goroutine that wants to read or write the list of active clients now has to send a request through a channel, and the monitor goroutine selects a channel with a pending request and fulfills the request. I also refactored some of the main logic by splitting out the denser sections of code into their own functions. * Fix race condition with accessing client names. * Fix client-side data races. This is a first pass at addressing multiple data races on the client side. The biggest change was serializing calls to Draw by sending on a single channel to eliminate concurrency. Most other changes utilized mutexes to protect concurrent read/write access of editor state. I no longer detect data races at runtime during normal local use. More rigorous detection could be done by increasing test coverage and running the Go race detector with the test suite. Not much consideration was given to performance. Profiling the client and server code with the 'block' and 'mutex' memory profiles could point to many areas for improvement. * ci: add race detector step --------- Co-authored-by: burntcarrot <[email protected]>
- Loading branch information
1 parent
d7a5677
commit a9d7b41
Showing
8 changed files
with
502 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.