Skip to content

Commit 5c2a9c5

Browse files
fix(audience): treat missing queue dir as empty queue in ReadBatch (SDK-341)
- DiskStore.ReadBatch was the one path that called Directory.GetFiles(_queueDir) without the DirectoryNotFoundException guard the rest of the methods (DeleteAll, ApplyAnonymousDowngrade, TryDelete) already use. - Linux Mono / IL2CPP test cells run a SetUp that deletes the SDK persistent dir between every test. A background flush timer started by the prior test can fire after the delete; the resulting GetFiles raised DirectoryNotFoundException which propagated through HttpTransport.SendBatchAsync to OnError, made the SampleApp log "flush() Err" instead of "flush() Ok", and failed the test. - Same shape was hitting Shutdown's flush path: the AggregateException the caller saw was wrapping the same DirectoryNotFoundException. - Catch + return Array.Empty<string>(). Empty result is the correct semantics: a deleted queue dir has no events to send. Surfaced by run 25539153233 once SDK-317 (PR #754) landed real Linux PlayMode coverage. Affected 9 cells (2 Mono, 7 IL2CPP) on Unity 6. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 54cbf4a commit 5c2a9c5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/Packages/Audience/Runtime/Transport/DiskStore.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,18 @@ internal IReadOnlyList<string> ReadBatch(int maxSize)
6565

6666
var result = new List<string>();
6767

68-
// Sort by filename (ticks prefix) → oldest first
69-
var files = Directory.GetFiles(_queueDir, "*.json")
70-
.OrderBy(f => Path.GetFileName(f), StringComparer.Ordinal);
68+
// Sort by filename (ticks prefix) → oldest first.
69+
// The queue dir can disappear out from under us when an external
70+
// process (test SetUp, manual cleanup, persistentDataPath wipe)
71+
// deletes it between SDK Init and the next flush tick. Treat that
72+
// as an empty queue rather than letting DirectoryNotFoundException
73+
// bubble up through SendBatchAsync to the caller's OnError.
74+
// Matches the existing guard in DeleteAll / ApplyAnonymousDowngrade.
75+
string[] paths;
76+
try { paths = Directory.GetFiles(_queueDir, "*.json"); }
77+
catch (DirectoryNotFoundException) { return Array.Empty<string>(); }
78+
79+
var files = paths.OrderBy(f => Path.GetFileName(f), StringComparer.Ordinal);
7180

7281
foreach (var path in files)
7382
{

0 commit comments

Comments
 (0)