summaryrefslogtreecommitdiff
path: root/index.go (unfollow)
Commit message (Collapse)AuthorFilesLines
13 daysREADME.md, iadocs/{cover*, crita*}: Update documentationRunxi Yu3-39/+67
13 dayscca.scfg.example: Listen on 127.0.0.1:5555 only by defaultRunxi Yu1-3/+3
I would have used IPv6, i.e. [::1]:5555, but our school network only has IPv4 and it'd be easier to keep everything on the same protocol, though this probably wouldn't matter for standard reverse proxy setups.
13 daysstyle.css: Update color schemeRunxi Yu1-22/+20
13 days{config,ws}.go, cca.scfg.example: Allow same-user fake authRunxi Yu3-15/+30
This is useful for testing whether connection collisions work well.
13 daysws.go: Don't log chanPool changesRunxi Yu1-2/+0
13 daysschema.sql: users.expr should be BIGINTRunxi Yu1-1/+1
13 days{ws,wsm}.go: Handle context cancellationsRunxi Yu2-5/+94
13 daysstudent.html: Connection closed could be cause by a login elsewhereRunxi Yu1-0/+3
13 dayslint.sh: Disable nonamedreturnsRunxi Yu1-1/+1
I used named returns to inspect return values (especially error values)
13 daysws.go: Fix memory leak introduced in last commitRunxi Yu1-0/+7
The entry is deleted from cancelPool if and only if cancelPool's cancel function for the user is equal to &newCancel. This compare-and-delete works because of locking.
13 daysws.go: Fix first race condition in cancelPool managementRunxi Yu1-13/+2
Cancel occurs in async. When the cancelled function exits, it deletes the entry in cancelPool, and could replace the new routine's cancel function, which is of course undesirable. Therefore this commit causes handleConn to stop deleting from cancelPool entirely. Note that this introduces a memory leak at the size of context.CancelFunc per user, because we are never deleting from cancelPool. This does not actually solve the race condition documented in fc911928 where two new connections start sufficiently close to each other.
14 days{main,ws,wsm}.go: Attempt to cancel old sessionsRunxi Yu3-23/+87
When beginning to handle a WebSocket connection, we shall create a new context, with the request context as its parent. We use the new context for everything from now on, except for reporting error messages, which is handled by creating a reportError function in a closure in makeReportError and passing it along to command-handling functions. Note that if one user attempts to rapidly launch WebSocket connections, there might still be a race condition where the old connection hasn't been completely established yet (i.e. an entry hasn't been added to cancelPool) and the new connection isn't able to cancel the old connection. I'm a bit tired to think of a solution now but it could probably be solved by moving the cancellation registration and cancelling sooner during the initial handshake. Note that more parts of the event loop needs to select from ctx.Done (from newCtx) for this to work reliably.
14 daysREADME.md, student.html: Correct spellingRunxi Yu2-2/+2
14 daysREADME.md: Remove CI badgesRunxi Yu1-6/+0
2024-10-02ws.go: Update comment on disallowed charactersRunxi Yu1-5/+4
2024-10-02student.html: Update error messages to be a bit more friendlyRunxi Yu1-6/+15
2024-10-02index.go, *.html: index->student, index_login->loginRunxi Yu3-5/+5
The new names are a bit more descriptive in what each do, and I intend to add an "admin" template in the future. This has no user-facing effects.
2024-10-02index{,_login}.html: Improve accessibilityRunxi Yu2-2/+4
2024-10-02main.js: Un-disable already-chosen courses during HELLO/HIRunxi Yu1-0/+1
2024-10-02index.html, style.css: Remove ID column because nobody caresRunxi Yu2-5/+3
2024-10-02main.js: Unset indeterminate when receiving NRunxi Yu1-0/+1
2024-10-02main.js: Set checkbox.indeterminate = true when uncheckingRunxi Yu1-1/+1
2024-10-02tcourse.sql: Add 1000 of each course for testingRunxi Yu1-5/+5
2024-10-02bench: Don't log errors for nowRunxi Yu1-3/+3
2024-10-02wsm.go, main.js: Use M for number, N for deselectRunxi Yu2-3/+6
Previously both commands used N, and deselection wasn't really implemented on the JavaScript side. It worked and didn't throw an exception but it's technically wrong and the user could see an empty number field for a split second.
2024-10-02Makefile: Add wsm.go to the source file listRunxi Yu1-1/+1
2024-10-02bench: Attempt to choose random coursesRunxi Yu1-4/+18
2024-10-02bench: Add initial benchmarking suiteRunxi Yu5-0/+106
Currently only connects and creates a fake user
2024-10-02{auth,utils,ws}.go: randomBytes -> randomStringRunxi Yu3-4/+4
2024-10-02{config,ws}.go, cca.scfg.example: Add fake auth supportRunxi Yu5-16/+72
Fake authentication is useful when benchmarking the server with an external program without going insane with the OpenID Connect forms.
2024-10-02style.css: message-box border 1pxRunxi Yu1-1/+1
2024-10-01{auth,db,wsm}.go: Make 23505 (uniqueness violation) a constantRunxi Yu3-2/+4
2024-10-01main.js: Only try to mark courses as checked if mar[1] !== ""v0.1.1Runxi Yu1-3/+5
Otherwise, users may get something like "TypeError: Cannot set properties of null (setting 'checked')"
2024-10-01main.js: Everything should be after DOMContentLoadedRunxi Yu1-99/+101
This is technically a race condition, and users with extremely slow computers and very bad luck might get exceptions from this. I think.
2024-10-01style.css: Make light header background lighterRunxi Yu1-1/+1
2024-10-01style.css: Remove thick table borderRunxi Yu1-1/+1
2024-10-01wsm.go, main.js: Display the user's selected courses on first runv0.1.0Runxi Yu2-2/+22
It's done in the WebSocket routines rather than in the template maker because it's relatively easier to write the logic this way.
2024-10-01style.css: Switch the header to a grey themeRunxi Yu1-4/+8
2024-10-01style.css: Revert back to blue themeRunxi Yu1-3/+5
2024-10-01{ws,wsm}.go: Split message handlers into their own functionsRunxi Yu2-124/+182
2024-10-01lint.sh: Disable dogsled and unparamRunxi Yu1-1/+1
dogsled forbids patterns such as "_, _, _ = a, b, c" for no reason. unparam warns about unused parameters even when I'm assigning them to _ to indicate that it's fine for them to be unused.
2024-10-01{auth,ws}.go: Remove unnecessary TODOsRunxi Yu2-19/+2
2024-10-01ws.go: Allow deselecting coursesRunxi Yu1-0/+34
2024-10-01lint.sh: Disable yet another cyclomatic complexity checkerRunxi Yu1-1/+1
2024-10-01ws.go: Fix logic error when reaffirming a course choiceRunxi Yu1-2/+2
When a user has already chosen a course choice but sends a message to choose it again, a database error occurs as the uniqueness constraint is violated. In this case, we "reaffirm" the user's course choice, to hopefully get their client's state back in sync. However, we previously forgot to return back to the event loop after this reaffirmation, causing the control flow to fall into the course-increment and transaction-commit stage. The error is discovered at tx.Commit, where pgx raises a ErrTxCommitRollback, because in that case we're trying to commit a transaction that has already encountered an error.
2024-10-01{main,pw}.go, Makefile, index_login.html: Remove password auth stubRunxi Yu4-92/+1
I don't think password authentication is really useful, since Microsoft Entra ID is the "proper" way of doing authentication in our school system and there's just little reason to have a password login. I previously wanted to use password authentication for stress testing, but stress testing really could just use completely fake authentication and there's no need for any password whatsoever.
2024-10-01ws.go: protocolError instead of R on unexpected database errorsRunxi Yu1-23/+7
When an unknown database error is encoutered, the connection should be considered broken and the error should be reported as a fatal error to the end user. Rejecting the course choice unsets the checkbox and lets the page to be continued to be used, which is not intended.
2024-10-01index.go, ws.go: Fix race condition surrounding coursesRunxi Yu2-13/+21
handleIndex and handleConn used to access the courses map without RLock'ing coursesLock, which may cause issues if courses is being written to, by a function such as setupCourses.
2024-10-01courses.go: Propagate course.Selected when setting up coursesRunxi Yu1-2/+7
2024-10-01ws.go: Decrement course.Selected counter on commit failuresRunxi Yu1-0/+6