-
Notifications
You must be signed in to change notification settings - Fork 19
fix: SSE streaming stall on MAUI Android (SDK-2755) #124
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fc46ea5
chore: add SSE contract-tests service
tanderson-ld cdd255a
fix: increase SSE read buffer to 8192 bytes to avoid Android streamin…
tanderson-ld 81a5118
chore: audit contract-tests capabilities against harness
tanderson-ld 3d0ff37
ci: run sse-contract-tests harness against the new test service
tanderson-ld 2091c9e
chore: match case-insensitive comparison on Content-Type lookup
tanderson-ld 8bded2d
chore: split TestService.cs into Program + Webapp for platform reuse
tanderson-ld ba7525a
ci: add Android contract-tests job
tanderson-ld 1843353
Apply suggestion from @jsonbailey
tanderson-ld 320e40a
Apply suggestion from @jsonbailey
tanderson-ld d16e077
Update .github/workflows/ci.yml
tanderson-ld c85d150
chore: tighten SDK-2755 buffer-size comment
tanderson-ld c238772
chore: drop cross-SDK pattern references from comments
tanderson-ld dc1fc75
ci: fix Android job -- pre-create AVD dir, capture logs in-scope
tanderson-ld 6f57f61
ci: skip basic parsing/large message in two chunks on Android
tanderson-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| TEMP_TEST_OUTPUT=/tmp/sse-contract-test-service.log | ||
|
|
||
| build-contract-tests: | ||
| @cd contract-tests && dotnet build TestService.csproj | ||
|
|
||
| start-contract-test-service: | ||
| @cd contract-tests && dotnet run --project TestService.csproj --no-build | ||
|
|
||
| start-contract-test-service-bg: | ||
| @echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)" | ||
| @make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 & | ||
|
|
||
| run-contract-tests: | ||
| @curl -s https://raw.githubusercontent.com/launchdarkly/sse-contract-tests/main/downloader/run.sh \ | ||
| | VERSION=v2 PARAMS="-url http://localhost:8000 -stop-service-at-end \ | ||
| -skip 'basic parsing/ID field is ignored if it contains a null' \ | ||
| -skip 'linefeeds/CR separator' \ | ||
| -skip 'linefeeds/CRLF where CR is end of 1 chunk' \ | ||
| -skip 'reconnection/discards partial messages on retry'" sh | ||
|
|
||
| contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests | ||
|
|
||
| # ---- Android contract tests ---- | ||
| # Requires: an Android emulator or device connected via adb, and the .NET 9 SDK with the | ||
| # android workload installed. See ci.yml's contract-tests-android job for how CI does this. | ||
|
|
||
| build-contract-tests-android: | ||
| @cd contract-tests-android && dotnet build ContractTestService.Android.csproj -c Debug | ||
|
|
||
| # Installs the built APK, launches the MainActivity, waits for the app to be listening, | ||
| # and forwards the local port to the emulator. All adb glue is in scripts/ so the CI | ||
| # workflow's script: block can stay a two-line call to make. | ||
| start-contract-test-service-android: | ||
| @scripts/start-android-test-service.sh | ||
|
|
||
| # -host 10.0.2.2 makes callback URLs the harness gives the test service point at the | ||
| # emulator's alias for the host machine (see Android emulator docs). Without this the | ||
| # service can't POST callbacks back through adb. | ||
| # | ||
| # The harness only supports inline -skip; we read the Android suppressions file line | ||
| # by line and translate each line into a `-skip 'X'` argument. | ||
| ANDROID_SUPPRESSIONS = contract-tests-android/testharness-suppressions.txt | ||
|
|
||
| run-contract-tests-android: | ||
| @SKIP_ARGS=""; \ | ||
| while IFS= read -r line; do SKIP_ARGS="$$SKIP_ARGS -skip '$$line'"; done < $(ANDROID_SUPPRESSIONS); \ | ||
| curl $${GITHUB_TOKEN:+ -H "Authorization: Token $${GITHUB_TOKEN}"} \ | ||
| -s https://raw.githubusercontent.com/launchdarkly/sse-contract-tests/main/downloader/run.sh \ | ||
| | VERSION=v2 PARAMS="-url http://localhost:8000 -host 10.0.2.2 -stop-service-at-end $$SKIP_ARGS" sh | ||
|
|
||
| contract-tests-android: build-contract-tests-android start-contract-test-service-android run-contract-tests-android | ||
|
|
||
| .PHONY: build-contract-tests start-contract-test-service start-contract-test-service-bg run-contract-tests contract-tests \ | ||
| build-contract-tests-android start-contract-test-service-android run-contract-tests-android contract-tests-android |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0-android</TargetFramework> | ||
| <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>ContractTestService.Android</RootNamespace> | ||
| <AssemblyName>ContractTestService.Android</AssemblyName> | ||
| <ApplicationId>com.launchdarkly.contracttestservice</ApplicationId> | ||
| <ApplicationVersion>1</ApplicationVersion> | ||
| <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
| <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> | ||
| <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> | ||
| <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
| <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
| <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
| <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> | ||
| <Nullable>disable</Nullable> | ||
| <!-- Disable Fast Deployment and embed assemblies into the APK. Fast Deployment ships | ||
| .NET assemblies via adb sync into a __override__ directory at runtime; if the sync | ||
| hasn't happened when the app launches, it aborts with "No assemblies found in ...". | ||
| For CI (fresh APK, single-shot install-and-run), we want everything in the APK. --> | ||
| <AndroidFastDeployment>false</AndroidFastDeployment> | ||
| <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="LaunchDarkly.TestHelpers" Version="2.0.0" /> | ||
| <PackageReference Include="LaunchDarkly.Logging" Version="2.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\src\LaunchDarkly.EventSource\LaunchDarkly.EventSource.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- The Android host and desktop host share the SSE contract-test service application | ||
| logic. Only the entry point (Program.cs desktop / MainActivity.cs Android) differs | ||
| between the two targets. --> | ||
| <ItemGroup> | ||
| <Compile Include="..\contract-tests\Representations.cs" Link="Representations.cs" /> | ||
| <Compile Include="..\contract-tests\StreamEntity.cs" Link="StreamEntity.cs" /> | ||
| <Compile Include="..\contract-tests\TestService.cs" Link="TestService.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Android.App; | ||
| using Android.OS; | ||
| using LaunchDarkly.TestHelpers.HttpTest; | ||
| using TestService; | ||
|
|
||
| namespace ContractTestService.Android | ||
| { | ||
| /// <summary> | ||
| /// Android entry point for the SSE contract-tests service. Starts the same Webapp used by | ||
| /// the desktop test service (contract-tests/) on a background thread when the activity | ||
| /// launches. The HTTP endpoints, capabilities list, and routing logic are all defined by | ||
| /// the shared Webapp class in TestService.cs -- this Activity only takes care of process | ||
| /// hosting on Android. | ||
| /// | ||
| /// The purpose of exercising the contract tests through this Android app is to route SSE | ||
| /// stream reads through AndroidMessageHandler + BufferedStream + the | ||
| /// Java InputStream chain, which is the platform-specific path where SDK-2755's stall bug | ||
| /// manifests. Running the harness against this app on an emulator is how we protect that | ||
| /// fix from regression. | ||
| /// </summary> | ||
| [Activity(Label = "ContractTestService", MainLauncher = true)] | ||
| public class MainActivity : Activity | ||
| { | ||
| const int Port = 8000; | ||
| const string LogTag = "ContractTestService"; | ||
|
|
||
| protected override void OnCreate(Bundle savedInstanceState) | ||
| { | ||
| base.OnCreate(savedInstanceState); | ||
| Task.Run(RunHttpServer); | ||
| } | ||
|
|
||
| private void RunHttpServer() | ||
| { | ||
| try | ||
| { | ||
| var quitSignal = new EventWaitHandle(false, EventResetMode.AutoReset); | ||
| var app = new Webapp(quitSignal); | ||
| var server = HttpServer.Start(Port, app.Handler); | ||
| server.Recorder.Enabled = false; | ||
| global::Android.Util.Log.Info(LogTag, $"Listening on port {Port}"); | ||
| quitSignal.WaitOne(); | ||
| server.Dispose(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| global::Android.Util.Log.Error(LogTag, $"HTTP server failed: {e}"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <!-- largeHeap gives the app the ~512 MB per-process heap limit instead of the default | ||
| ~192 MB. Needed for the payload-size sweep in sse-contract-tests to exercise the | ||
| largest sizes (up to 128 MiB payloads inflate to ~500+ MB peak footprint through | ||
| UTF-16 decoding and JSON serialization). --> | ||
| <application android:label="ContractTestService" android:usesCleartextTraffic="true" android:largeHeap="true" /> | ||
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| basic parsing/ID field is ignored if it contains a null | ||
| basic parsing/large message in two chunks | ||
| linefeeds/CR separator | ||
| linefeeds/CRLF where CR is end of 1 chunk | ||
| reconnection/discards partial messages on retry | ||
| HTTP behavior/REPORT request | ||
| reconnection/caller can trigger a restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using System.Threading; | ||
| using LaunchDarkly.TestHelpers.HttpTest; | ||
|
|
||
| namespace TestService | ||
| { | ||
| /// <summary> | ||
| /// Desktop / server entry point for the SSE contract-tests service. The Webapp class | ||
| /// (in TestService.cs) is shared with the Android target under contract-tests-android/, | ||
| /// which has its own Activity-based entry point. | ||
| /// </summary> | ||
| public class Program | ||
| { | ||
| const int Port = 8000; | ||
|
|
||
| public static void Main(string[] args) | ||
| { | ||
| var quitSignal = new EventWaitHandle(false, EventResetMode.AutoReset); | ||
|
|
||
| var app = new Webapp(quitSignal); | ||
| var server = HttpServer.Start(Port, app.Handler); | ||
| server.Recorder.Enabled = false; | ||
|
|
||
| System.Console.WriteLine("Listening on port {0}", Port); | ||
|
|
||
| quitSignal.WaitOne(); | ||
| server.Dispose(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # SSE contract-tests service | ||
|
|
||
| This is a small HTTP service that wraps `LaunchDarkly.EventSource` and exposes it to | ||
| the [`sse-contract-tests`](https://github.com/launchdarkly/sse-contract-tests) harness. | ||
|
|
||
| The service is not shipped as part of any published NuGet package. It exists purely | ||
| as a test target for the `sse-contract-tests` harness. | ||
|
|
||
| ## Running | ||
|
|
||
| ``` | ||
| dotnet run --project TestService.csproj | ||
| ``` | ||
|
|
||
| The service listens on port 8000 by default. | ||
|
|
||
| ## Running the harness against it | ||
|
|
||
| Either use the released harness binary via `sse-contract-tests`'s `downloader/run.sh` | ||
| script, or build the harness locally: | ||
|
|
||
| ``` | ||
| cd path/to/sse-contract-tests | ||
| go build -o sse-test-harness . | ||
| ./sse-test-harness --url http://localhost:8000 | ||
| ``` | ||
|
|
||
| To exercise only a subset of tests, pass `--run <pattern>` or `--skip <pattern>`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| // Note, in order for System.Text.Json serialization/deserialization to work correctly, the members of | ||
| // these classes must be properties with get/set, rather than fields. The property names are automatically | ||
| // camelCased by System.Text.Json. | ||
|
|
||
| namespace TestService | ||
| { | ||
| public class Status | ||
| { | ||
| public string[] Capabilities { get; set; } | ||
| } | ||
|
|
||
| public class StreamOptions | ||
| { | ||
| public string StreamUrl { get; set; } | ||
| public string CallbackUrl { get; set; } | ||
| public string Tag { get; set; } | ||
| public Dictionary<string, string> Headers { get; set; } | ||
| public int? InitialDelayMs { get; set; } | ||
| public int? ReadTimeoutMs { get; set; } | ||
| public string LastEventId { get; set; } | ||
| public string Method { get; set; } | ||
| public string Body { get; set; } | ||
| } | ||
|
|
||
| public class Message | ||
| { | ||
| public string Kind { get; set; } | ||
| public EventMessage Event { get; set; } | ||
| public string Comment { get; set; } | ||
| public string Error { get; set; } | ||
| } | ||
|
|
||
| public class EventMessage | ||
| { | ||
| public string Type { get; set; } | ||
| public string Data { get; set; } | ||
| public string Id { get; set; } | ||
| } | ||
|
|
||
| public class CommandParams | ||
| { | ||
| public string Command { get; set; } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.