Skip to content

fix(logging): crash in release builds #3971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

fix(logging): crash in release builds #3971

wants to merge 1 commit into from

Conversation

harsh62
Copy link
Member

@harsh62 harsh62 commented Mar 24, 2025

Issue #

#3970

Description

Users are experiencing crashes in release builds when using CloudWatch logging during login. The crash occurs in CloudWatchLoggingConsumer.ensureLogStreamExists() due to memory management issues related to Swift async/await operations.

This is a regression introduced in PR #3731, which refactored CloudWatch logging components to address strict concurrency warnings.

Root Cause

The crash occurs because:

  1. CloudWatchLoggingStreamNameFormatter.formattedStreamName() was changed from synchronous to asynchronous
  2. deviceIdentifier was changed from a stored property to a computed property with an async getter
  3. The implementation didn't safely handle memory management across async suspension points
  4. Release mode optimizations expose concurrency issues not apparent in debug builds

Solution

This PR addresses the issue by:

  1. Restructuring the ensureLogStreamExists() method to properly handle async operations
  2. Adding comprehensive error handling with fallbacks
  3. Safely managing memory across async suspension points
  4. Only marking operations as complete after successful execution
  5. Adding logging to help diagnose similar issues in the future

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented Mar 25, 2025

Codecov Report

Attention: Patch coverage is 69.56522% with 14 lines in your changes missing coverage. Please review.

Project coverage is 67.80%. Comparing base (75c8827) to head (3172ade).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ingPlugin/Consumer/CloudWatchLoggingConsumer.swift 69.56% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3971      +/-   ##
==========================================
+ Coverage   67.66%   67.80%   +0.13%     
==========================================
  Files        1128     1128              
  Lines       52246    52275      +29     
==========================================
+ Hits        35354    35444      +90     
+ Misses      16892    16831      -61     
Flag Coverage Δ
API_plugin_unit_test 70.33% <ø> (ø)
AWSPluginsCore 69.34% <ø> (ø)
Amplify 47.82% <ø> (ø)
Analytics_plugin_unit_test 85.20% <ø> (ø)
Auth_plugin_unit_test 73.63% <ø> (+0.05%) ⬆️
DataStore_plugin_unit_test 84.11% <ø> (+0.71%) ⬆️
Geo_plugin_unit_test 74.86% <ø> (ø)
Logging_plugin_unit_test 63.01% <69.56%> (-0.11%) ⬇️
Predictions_plugin_unit_test 35.40% <ø> (ø)
PushNotifications_plugin_unit_test 88.43% <ø> (ø)
Storage_plugin_unit_test 76.88% <ø> (ø)
unit_tests 67.80% <69.56%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant