Repository navigation
Conversation
Sending, editing and deleting a message each read the group's whole messages file from S3, change it and write the file back, with no lock. Two at once both read the same old copy, so the later write dropped the other's change: two people sending at the same moment lost a message, and an edit or delete during a send lost the edit or the new message. They now take one lock per group, the same pattern as the shared-files metadata lock. Reads don't wait, and other groups don't wait on each other. The lock only works within one server. Several servers writing the same file would need S3's conditional writes instead. Tests run two sends, an edit and a send, and a delete and a send at once against an S3 stub that holds each read until the other one has started.
The storage notes said every send rewrites the file with no lock, and Known issues listed two sends at once losing one. The note now says sending, editing and deleting take one lock per group, within one server only. The testing list names GroupChatServiceTest, and the known issue is gone.
A send reads the group's whole messages file, adds the message and writes
the file back. decodeFile answers null for any failure, not only a missing
file, so when S3 timed out, was throttled or answered a 5xx, the send took
the chat for empty and wrote the one new message over the whole history. It
still answered 200 and broadcast the message.
The send now reads with a strict decodeFileOrThrow, like fileExistsOrThrow:
only S3's 404 means no messages yet. A timeout, no connection or a 5xx
throws MessagesReadFailedException, nothing is saved or broadcast, and
POST /api/groups/chat/{id}/messages answers 503 with Retry-After, the same
as a shared-file check that fails. S3 refusing the read (a 4xx) or a bug
here also writes nothing and gets the route's usual 400, since waiting
won't fix it. S3 failures to read are logged with their cause. Without S3
settings a send still broadcasts live, as before. decodeFile, edits and
deletes are unchanged.
Tests send through the controller to a real S3FileHandler over a stand-in
S3 client: a 503 and a timeout keep the stored file byte for byte and
answer 503, a 403 and a bug write nothing and get no retry, a missing file
starts the history, and a server without S3 still broadcasts. The two older
tests that stub S3 now stub the strict read a send makes.
The send route and the storage notes now say a send reads the messages file with decodeFileOrThrow: S3 being unavailable answers 503 with Retry-After and nothing is saved or broadcast, S3 refusing the read or a bug gets the route's usual 400, and edits and deletes still read with decodeFile. The testing list gets a bullet for GroupChatSendTest and S3FileHandlerDecodeTest, with the command that runs the S3 handler tests.
This was referenced Nov 26, 2026
…or's types GroupChatSendTest built GroupChatApiController, GroupChatRealtimeService and GroupChatReadService by naming their constructors. Open PRs add constructor dependencies to the controller and the realtime service (Open-Coding-Society#302 a MessageReactionService, Open-Coding-Society#303 a MentorAccess), so once one of them and this test were both on master, the tests would stop compiling, with no merge conflict to show it. TestBeans builds a class through its biggest constructor: each parameter gets the first object the test passes that fits it, and a Mockito mock otherwise. The test then keeps compiling and running whatever dependencies those classes gain.
At every start, StartupService checks each group's messages file and creates an empty one for a group that has none. The check used fileExists, which reads any failure (a throttle, a 5xx, a timeout) as a missing file, so a check that failed at boot wrote an empty file over that group's whole history. ensureGroupStorageExists now checks with fileExistsOrThrow: only S3's 404 creates the file, and any other failure throws before anything is written. StartupService logs that group with the cause and goes on to the next one, so the server still starts. The check holds the group's message lock, so a message sent while the server is starting isn't written over, and a server without S3 settings checks nothing (S3FileHandler.isConfigured). The shared-files/ placeholder keeps the lenient check: it is empty, so writing it again loses nothing.
The storage notes now say StartupService creates a group's empty messages file and shared-files/ placeholder only when S3 answers 404 (fileExistsOrThrow). Any other failure to check is logged and leaves that group as it is, the other groups are still checked, the check holds the group's message lock, and a server without S3 settings checks nothing. The testing list gets a bullet for StartupServiceTest, with its command.
svaka2000
force-pushed
the
fix/group-chat-startup-check
branch
from
November 26, 2026 04:26
e45c359 to
1bc72b0
Compare
Contributor
Author
|
Combined into #314 with the same commits. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restarting Spring can't wipe a group chat's history anymore when S3 fails during the start-up check.
It's built on #297, which is built on #296 (all four of these change
GroupChatService), so those two merge first, in that order; until then this diff includes both, and this PR's own commits start at "Group chat: a restart keeps the history when S3 can't check it".StartupServicechecks each group's messages file and creates an empty one for a group that doesn't have it. The check usedfileExists, which returns false for any failure, not only a missing file.ensureGroupStorageExistsnow checks withfileExistsOrThrow, the strict check from Group chat files: an index without the bytes, one-file downloads, and no overwriting #280. Only a 404 from S3 (no file at that path) creates the empty file, and any other failure throws before anything is written.StartupServicelogs that group with the cause and goes on to the next one, so one group can't stop Spring from starting. That group is checked again on the next start, and its chat works until then.StartupServiceruns, so the check holds the group's message lock from Group chat: a lock per group so two sends at once can't lose a message #296, and a message sent during the check can't be written over by the empty file.shared-files/placeholder (an empty file that marks the group's shared files folder) still usesfileExists, since writing it again loses nothing.Other notes:
StartupServiceTest, which runs the start-up check against a stand-in S3 client. A failed check leaves the history as it is and logs the group and the cause, and one group that can't be checked doesn't stop the others.StartupServiceandGroupChatService, five of the seven fail: a failed check writes an empty file over the history, and a message sent during the check is lost.docs/group-chat-architecture.mdI updated the storage notes and addedStartupServiceTestto the testing list.ImportPersonPasswordTest, which needs a local.env, andPersonCapstoneApprovalRouteTest, which fails the same way on master b94d9f3 (its Spring context doesn't load).How to try it:
./mvnw test -Dtest=StartupServiceTest.