Concurrent writes: optimistic concurrency (version + If-Match → 412) so a co-editor's save is never lost silently
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #562 của @silverbackdan — đã merge
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by tracing LastWriteResolver and how writable resources are serialized and updated; the payload does not name source files or tests. Check how versions could cover drafts, published resources, publish, and order changes, then review ETag and CORS handling. Done means writes with stale If-Match return 412 with the current resource, while writes without it continue to work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Two admins saving the same field of the same resource at the same moment lose one save silently. Found while porting the TipTap co-editing reference (components-web-app/cwa-nuxt-module#429) with @cwa/nuxt 2.0.0-alpha.28 and this bundle at 2.0.0-alpha.35.
Reproduced
One HtmlContent draft open in two tabs (each with its own X-CWA-Client-Id), both typing in the same editor:
- The two PATCHes went out 1 ms apart, and both returned 200.
- Each body was the tab's whole
html, built from what that tab had before the other's save, so the second commit replaced the first. Neither client can tell that its save was overwritten. - In one run the PATCH responses carried
lastWrite.at17:00:36.235 (A) and 17:00:36.219 (B), and the stored html was A's.
Why the module can't settle it alone
lastWrite.at is stamped the first time the resource is serialised in the request (LastWriteResolver), not in commit order. With two workers a few milliseconds apart, the save that commits last can carry the earlier time. The module drops an update older than its stored copy, so a tab can drop the update that actually won and stay out of step with the stored data. That happened on the template stack in 3/3 runs.
Proposal: optimistic concurrency on writes
- Every writable resource exposes a version that changes on each write. Doctrine's
#[ORM\Version]integer would do, or an opaque token. Serialise it, for example in_metadata, and send it as the responseETag. - A PATCH (and PUT/DELETE) with
If-Matchsucceeds only if the stored version still matches; otherwise 412 Precondition Failed, with the current resource in the body so the client does not need a second request. - Without
If-Match, writes behave as now, so non-realtime clients keep working. - The version on Mercure updates lets a client order updates by version instead of by
lastWrite.at. - To decide: whether the version covers draft and published as one resource (the module treats them as one for conflicts), and how a publish (a draft's PATCH that removes the draft) and the order PATCH /
/movetake part. - CORS: expose
ETagand allowIf-Matchfor cross-origin apps.
Module side, once released
The module sends If-Match from the stored version on each save. On a 412 it shows the field's existing conflict (Use theirs / Keep mine) with the body as theirs, and Keep mine re-sends with the new version. It orders Mercure updates by version.
- Ngôn ngữ chính
- PHP
- Star
- 32
- Fork
- 8
- Merge trung bình
- 56 phút
- Pull request đã merge (30 ngày)
- 164
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của components-web-app/api-components-bundle
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
components-web-app/api-components-bundle#333 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
components-web-app/api-components-bundle#325 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
components-web-app/api-components-bundle#259 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
components-web-app/api-components-bundle#186 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của components-web-app/api-components-bundle
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
litespeedtech/lscache_wp#1079 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 71/100
Automattic/blocks-engine#3438 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
FriendsOfFlarum/upload#549 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
getgrav/grav-plugin-api#66 ·