Skip to content

Commit 82a8518

Browse files
committed
[fix] Clarify SSL closure fallback classification
Centralize the transport-closure message fallback and cover the known runtime variants while keeping structured socket checks first. Made-with: Cursor
1 parent 3c94712 commit 82a8518

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/ByteSync.Client/Services/Communications/Transfers/Strategies/UploadFailureClassifier.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ namespace ByteSync.Services.Communications.Transfers.Strategies;
99

1010
public static class UploadFailureClassifier
1111
{
12+
private static readonly string[] UnexpectedTransportClosureMessageFragments =
13+
{
14+
"unexpected EOF",
15+
"0 bytes from the transport stream",
16+
};
17+
1218
public static UploadFileResponse Classify(Exception exception, CancellationToken cancellationToken)
1319
{
1420
if (exception is OperationCanceledException && cancellationToken.IsCancellationRequested)
@@ -56,7 +62,7 @@ or SocketError.HostDown
5662
or SocketError.HostUnreachable;
5763
}
5864

59-
if (current is IOException ioException && IsUnexpectedTransportClosure(ioException))
65+
if (current is IOException ioException && HasUnexpectedTransportClosureMessage(ioException))
6066
{
6167
return true;
6268
}
@@ -67,9 +73,16 @@ or SocketError.HostDown
6773
return false;
6874
}
6975

70-
private static bool IsUnexpectedTransportClosure(IOException exception)
76+
private static bool HasUnexpectedTransportClosureMessage(IOException exception)
7177
{
72-
return exception.Message.Contains("unexpected EOF", StringComparison.OrdinalIgnoreCase)
73-
|| exception.Message.Contains("0 bytes from the transport stream", StringComparison.OrdinalIgnoreCase);
78+
foreach (var fragment in UnexpectedTransportClosureMessageFragments)
79+
{
80+
if (exception.Message.Contains(fragment, StringComparison.OrdinalIgnoreCase))
81+
{
82+
return true;
83+
}
84+
}
85+
86+
return false;
7487
}
7588
}

tests/ByteSync.Client.UnitTests/Services/Communications/Transfers/Strategies/UploadFailureClassifierTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ public void Classify_HttpRequestExceptionWithConnectionReset_ShouldReturnClientN
110110
response.Exception.Should().BeSameAs(ex);
111111
}
112112

113-
[Test]
114-
public void Classify_HttpRequestExceptionWithUnexpectedEof_ShouldReturnClientNetworkError()
113+
[TestCase("Received an unexpected EOF from the transport stream.")]
114+
[TestCase("Received 0 bytes from the transport stream.")]
115+
public void Classify_HttpRequestExceptionWithUnexpectedTransportClosureMessage_ShouldReturnClientNetworkError(string message)
115116
{
116117
using var cts = new CancellationTokenSource();
117-
var ioException = new IOException("Received an unexpected EOF or 0 bytes from the transport stream.");
118+
var ioException = new IOException(message);
118119
var ex = new HttpRequestException("The SSL connection could not be established, see inner exception.", ioException);
119120

120121
var response = UploadFailureClassifier.Classify(ex, cts.Token);

0 commit comments

Comments
 (0)