Fix Android memfd buffer registration rollback#82
Merged
Conversation
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 the server could not provide, causing reload failures and an eventual abort when a slot referenced the missing buffer. 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.
…create CreateSplitSharedMemoryBuffer referenced the memfd `fd` after the #ifdef __NR_memfd_create / #else block, so building the Android shmem path on a platform without memfd_create (e.g. macOS) failed to compile. Move the descriptor handling inside the #ifdef so the unsupported path just returns UnimplementedError. Also skip AndroidBufferRegistrationTest when memfd_create is unavailable instead of failing, so the Android shmem mode can be built and exercised on macOS.
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.
Bug and impact
On Android non-split memfd channels,
PublisherImpl::CreateOrAttachBuffersadvancedccb_->num_buffersbefore registering the new buffer FD with the server. IfRegisterClientBufferfailed 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_bufferscount or clearing the publisher's local unregistered buffer state.Fix
Roll back
ccb_->num_bufferson 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 makeSUBSPACE_SHMEM_MODEoverridable 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_ANDROIDbazelisk test //client:client_test --test_filter=ClientTest.Resize1:ClientTest.ResizeCallbackbazelisk test //client:client_testbazelisk test //client:client_test --cxxopt=-DSUBSPACE_SHMEM_MODE=SUBSPACE_SHMEM_MODE_ANDROIDRe-created from #81 so the commit is authored under a CLA-covered account; supersedes #81.