Skip to content

Fix Android memfd buffer registration rollback#81

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-857e
Closed

Fix Android memfd buffer registration rollback#81
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-857e

Conversation

@cursor

@cursor cursor Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

On Android non-split memfd channels, PublisherImpl::CreateOrAttachBuffers advanced ccb_->num_buffers before registering the new buffer FD with the server. If RegisterClientBuffer failed after that CAS, subscribers could observe a new buffer generation that the server could not provide, causing reload failures and eventual abort when a slot referenced the missing buffer.

Root cause

The Android FD broker requires server registration before other clients can map a buffer, but the error path returned without rolling back the shared num_buffers count or clearing the publisher's local unregistered buffer state.

Fix

Roll back ccb_->num_buffers on registration failure when it still points at the failed generation, clear the corresponding BCB sizes, and unmap/drop local buffers beyond the last fully registered generation. Also make SUBSPACE_SHMEM_MODE overridable so the Android memfd path can be tested on Linux, and update memfd includes accordingly.

Validation

  • bazelisk test //client:client_test --test_filter=AndroidBufferRegistrationTest.FailedRegistrationRollsBackNumBuffers --cxxopt=-DSUBSPACE_SHMEM_MODE=SUBSPACE_SHMEM_MODE_ANDROID
  • bazelisk test //client:client_test --test_filter=ClientTest.Resize1:ClientTest.ResizeCallback
  • bazelisk test //client:client_test
  • bazelisk test //client:client_test --cxxopt=-DSUBSPACE_SHMEM_MODE=SUBSPACE_SHMEM_MODE_ANDROID
Open in Web View Automation 

Co-authored-by: dallison <dallison@users.noreply.github.com>
@dallison

dallison commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Superseded by #82, which contains the same fix re-authored under a CLA-covered account (plus a build/test fix for the Android shmem path on platforms without memfd_create).

@dallison dallison closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants