Open
Description
Bug Description
The MessagingService._delete()
method in the Firebase Messaging SDK has a memory leak issue where resources are not properly cleaned up when the service is deleted.
Root Cause
The current implementation of MessagingService._delete()
only returns Promise.resolve()
without cleaning up:
- Timer leak: The logging service starts a recursive
setTimeout
loop via_processQueue()
that continues indefinitely - Event listener leak: Event listeners added in factory functions are never removed
- Missing cleanup: No cleanup of message handlers, log events, or service worker references
Impact
- Memory leaks when Firebase messaging service is deleted
- Timers continue running in the background
- Event listeners remain attached
- Potential performance degradation over time
Affected Code
packages/messaging/src/messaging-service.ts
-_delete()
methodpackages/messaging/src/helpers/logToFirelog.ts
-_processQueue()
timer managementpackages/messaging/src/helpers/register.ts
- Event listener registration
Comparison with Other Services
Other Firebase services like AppCheckService
properly clean up their resources in _delete()
methods by removing listeners and clearing state.
Proposed Solution
Implement proper resource cleanup in MessagingService._delete()
including:
- Clear logging timers
- Remove event listeners
- Reset all properties to initial state
- Clear message handlers and log events
- Provide cleanup mechanism for registered cleanup functions
Environment
- Firebase JS SDK version: 11.8.1
- Affects both browser and service worker environments