Functions: Add in function streaming#1478
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces Server-Sent Event (SSE) streaming support for callable functions in the Firebase Unity SDK, adding the StreamAsync API and a new StreamResponse class, along with corresponding integration tests and dependency updates. The review feedback highlights two important improvements in HttpsCallableReference.cs: first, the HttpResponseMessage returned by SendAsync should be disposed to prevent connection leaks when using HttpCompletionOption.ResponseHeadersRead; second, a null check should be added for response.Content before reading the stream to avoid potential null reference exceptions.
| #endif | ||
|
|
||
| // Use ResponseHeadersRead to avoid loading the whole stream at once. | ||
| var response = await _firebaseFunctions.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); |
There was a problem hiding this comment.
The HttpResponseMessage returned by SendAsync is not disposed. When using HttpCompletionOption.ResponseHeadersRead, the underlying network connection remains active and open until the response is explicitly disposed. Failing to dispose it can lead to connection leaks, especially if the stream is not fully consumed or if an exception is thrown during iteration. Please use using var response to ensure proper resource cleanup.
using var response = await _firebaseFunctions.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for Callable Functions Streaming in Firebase Functions via the new StreamAsync API, utilizing Server-Sent Events (SSE). It includes the implementation of StreamResponse to represent intermediate messages and final results, SSE stream parsing logic, and corresponding integration tests. Feedback on the changes suggests improving the streaming implementation by properly disposing of HttpRequestMessage, combining cancellation tokens, and ensuring responsive cancellation during stream reads.
Description
Functions: Add in function streaming
Testing
Ran the test locally in unity editor and created a new integration test
Type of Change
Place an
xthe applicable box: