Subscription Cleanup
EdgeInteract manages most subscription cleanup automatically. This page documents what is cleaned up automatically, what requires manual cleanup, and how to verify there are no subscription leaks in your application.
Automatic Cleanup
The following subscriptions are cleaned up automatically by the EdgeInteract packages:
| Subscription | Cleaned Up When | Managed By |
|---|---|---|
interactions.{userId} | On InteractionProvider unmount or EdgeStream disconnect | InteractionProvider |
interactions.dismiss.{userId} | On InteractionProvider unmount | InteractionProvider |
interactions.callback.{interactionId} | After response or timeout received | InteractionPipeline (server) |
interactions.ack.{interactionId} | After ack received or ack timeout | InteractionResponsePublisher (client) |
React Cleanup via useEffect
When using the React bindings, cleanup is handled automatically via React's useEffect cleanup function. The InteractionProvider ensures all subscriptions are cleaned up on unmount:
// Inside InteractionProvider (simplified)
useEffect(() => {
const subscriber = new InteractionSubscriber();
subscriber.start(currentUser.id, interactionQueue);
return () => {
// Cleanup runs on unmount or when currentUser.id changes
subscriber.stop();
};
}, [currentUser.id]);
Manual Cleanup for Custom Subscriptions
If you create your own EdgeStream subscriptions for interaction topics (not recommended — use the provided hooks), you must clean them up manually:
// Manual subscription cleanup — only if bypassing the built-in provider
const sub = await edgeStreamClient.subscribe('interactions.custom.topic', handler);
// In cleanup / useEffect return:
return () => {
sub.unsubscribe();
};
Verifying No Subscription Leaks
The EdgeInteract observability package exposes an active subscription count. Use the InteractionMonitor component to verify:
- Active callback subscriptions should equal the number of in-flight interactions
- A growing count of active callback subscriptions (over time) indicates a leak
- The subscription count should drop to 0 when all interactions are resolved and the user logs out
InteractionProvider and the built-in React hooks, subscription cleanup is fully automatic. You only need to worry about cleanup if you bypass the provider and use the client package directly.