Fix simulator putfile posix error#16386
Conversation
Disables background session on simulator for putFile to workaround a QUIC EMSGSIZE error, formats POSIX errors properly, and adds an integration test.
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where putFile fails on the iOS Simulator with POSIX errno 40 (EMSGSIZE) by disabling background session uploads in simulator environments. It also improves error formatting for NSPOSIXErrorDomain errors and ensures testBlock is correctly propagated across all fetcher services. Feedback on these changes includes a recommendation to use Int32(truncatingIfNeeded:) to prevent potential crashes when formatting POSIX errors, a suggestion to simplify the conditional compilation block for simulator checks, and a best-practice recommendation to clean up temporary files created during integration testing.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where putFile fails on the iOS Simulator with POSIX errno 40 (EMSGSIZE) by disabling background session uploads on simulator targets. It also improves error formatting for NSPOSIXErrorDomain errors and ensures testBlock is propagated to all fetcher services. The feedback suggests simplifying the new integration test by removing the redundant do-catch block and adding a dedicated unit test to verify the POSIX error formatting logic.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where putFile fails on the iOS Simulator with POSIX errno 40 (EMSGSIZE) by disabling background session uploads on simulator targets, propagating test blocks to all fetcher services, and improving error formatting for NSPOSIXErrorDomain errors. The review feedback suggests replacing the thread-unsafe strerror function with strerror_r to avoid potential race conditions, and utilizing defer blocks in the unit tests to guarantee proper cleanup of global test blocks and temporary files in case of test failures.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where putFile could fail on the iOS Simulator with POSIX errno 40 (EMSGSIZE) due to a QUIC bug in background sessions. It disables background sessions on the simulator, improves error formatting for NSPOSIXErrorDomain errors using strerror_r, and ensures test blocks are correctly propagated to all active fetcher services. Feedback on these changes includes a recommendation to wrap the multi-statement default branch in StorageError.swift in an immediately-invoked closure to prevent potential compilation failures in Swift 5.9+ switch expressions, as well as a suggestion to simplify nested dictionary iteration in StorageFetcherService.swift by using .values.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request resolves an issue where putFile fails on the iOS Simulator with POSIX errno 40 (EMSGSIZE) due to a QUIC bug in background sessions. It disables background sessions on the simulator, improves error formatting for NSPOSIXErrorDomain errors, updates test block propagation in StorageFetcherService, and adds corresponding tests. The review feedback suggests simplifying the conditional compilation block in StorageUploadTask.swift to avoid duplicating assignments, and refactoring the immediately-invoked closure in StorageError.swift using a ternary operator and strerror for better readability.
Fix Storage
putFilePOSIX error 40 on iOS SimulatorDescription
This PR addresses issue #16351 where
putFilefails on the iOS Simulator roughly 1.5–2.5 seconds after starting withError Domain=FIRStorageErrorDomain Code=-13000 "Unexpected 40 code from backend".The root cause is a known bug in the
nsurlsessiondQUIC receive path on the iOS Simulator, which incorrectly surfaces aPOSIX errno 40(EMSGSIZE/ Message too long) when transferring large datagrams via a background URL session.Fixes implemented:
StorageUploadTaskto explicitly disable background sessions when running on the simulator (#if targetEnvironment(simulator)). This routes the upload through a standard foregroundNSURLSessionin the app process, cleanly bypassing the buggynsurlsessiondQUIC path. The behavior on real physical devices remains completely unchanged.StorageError.swiftto properly catch and format underlyingNSPOSIXErrorDomainerrors. Instead of the confusing and incorrect"Unexpected 40 code from backend"message, developers will now see an accurate translation, such as"POSIX errno 40 (Message too long)", preventing wasted time debugging backend configurations for local networking failures.GTMSessionFetcherServicecaching fix: UpdatedStorageFetcherServiceso that whenupdateTestBlockis called during test suites, the test block is correctly applied and propagated to all pre-cachedGTMSessionFetcherServicebuckets, ensuring reliable mock interception during tests.StoragePOSIXErrorTest) that naturally validates theputFileAsyncflow successfully uploads the payload on the simulator without throwing EMSGSIZE.Related Issues
Fixes #16351
Testing
FirebaseStorageIntegrationtest suite locally.StoragePOSIXErrorTestproperly completes a file upload task on the iOS simulator environment without throwing anEMSGSIZEabort.