@@ -17,6 +17,7 @@ namespace Sentry.Internal.Http;
1717internal class CachingTransport : ITransport , IDisposable
1818{
1919 private const string EnvelopeFileExt = "envelope" ;
20+ private const string ProcessingFolder = "__processing" ;
2021
2122 private readonly ITransport _innerTransport ;
2223 private readonly SentryOptions _options ;
@@ -77,7 +78,7 @@ private CachingTransport(ITransport innerTransport, SentryOptions options, bool
7778 options . TryGetProcessSpecificCacheDirectoryPath ( ) ??
7879 throw new InvalidOperationException ( "Cache directory or DSN is not set." ) ;
7980
80- _processingDirectoryPath = Path . Combine ( _isolatedCacheDirectoryPath , "__processing" ) ;
81+ _processingDirectoryPath = Path . Combine ( _isolatedCacheDirectoryPath , ProcessingFolder ) ;
8182 }
8283
8384 private void Initialize ( bool startWorker )
@@ -271,6 +272,13 @@ private async Task ProcessCacheAsync(CancellationToken cancellation)
271272 // Signal that we can start waiting for _options.InitCacheFlushTimeout
272273 _preInitCacheResetEvent ? . Set ( ) ;
273274
275+ // Make sure no files got stuck in the processing directory
276+ // See https://github.com/getsentry/sentry-dotnet/pull/3438#discussion_r1672524426
277+ if ( _options . NetworkStatusListener is { Online : false } listener )
278+ {
279+ MoveUnprocessedFilesBackToCache ( ) ;
280+ }
281+
274282 // Process the cache
275283 _options . LogDebug ( "Flushing cached envelopes." ) ;
276284 while ( await TryPrepareNextCacheFileAsync ( cancellation ) . ConfigureAwait ( false ) is { } file )
@@ -288,6 +296,13 @@ private async Task ProcessCacheAsync(CancellationToken cancellation)
288296 }
289297 }
290298
299+ private static bool IsNetworkError ( Exception exception ) =>
300+ exception switch
301+ {
302+ HttpRequestException or WebException or IOException or SocketException => true ,
303+ _ => false
304+ } ;
305+
291306 private async Task InnerProcessCacheAsync ( string file , CancellationToken cancellation )
292307 {
293308 if ( _options . NetworkStatusListener is { Online : false } listener )
@@ -327,9 +342,12 @@ private async Task InnerProcessCacheAsync(string file, CancellationToken cancell
327342 // Let the worker catch, log, wait a bit and retry.
328343 throw ;
329344 }
330- catch ( Exception ex ) when ( ex is HttpRequestException or WebException or SocketException
331- or IOException )
345+ catch ( Exception ex ) when ( IsNetworkError ( ex ) )
332346 {
347+ if ( _options . NetworkStatusListener is PollingNetworkStatusListener pollingListener )
348+ {
349+ pollingListener . Online = false ;
350+ }
333351 _options . LogError ( ex , "Failed to send cached envelope: {0}, retrying after a delay." , file ) ;
334352 // Let the worker catch, log, wait a bit and retry.
335353 throw ;
0 commit comments