@@ -46,7 +46,7 @@ public interface ISyncSessionController
46
46
}
47
47
48
48
// These values are the config option names used in the registry. Any option
49
- // here can be configured with `(Debug)?Mutagen :OptionName` in the registry.
49
+ // here can be configured with `(Debug)?MutagenController :OptionName` in the registry.
50
50
//
51
51
// They should not be changed without backwards compatibility considerations.
52
52
// If changed here, they should also be changed in the installer.
@@ -141,7 +141,7 @@ public async Task<List<SyncSession>> ListSyncSessions(CancellationToken ct)
141
141
// reads of _sessionCount are atomic, so don't bother locking for this quick check.
142
142
switch ( _sessionCount )
143
143
{
144
- case - 1 :
144
+ case < 0 :
145
145
throw new InvalidOperationException ( "Controller must be Initialized first" ) ;
146
146
case 0 :
147
147
// If we already know there are no sessions, don't start up the daemon
@@ -162,33 +162,14 @@ public async Task Initialize(CancellationToken ct)
162
162
_sessionCount = - 2 ; // in progress
163
163
}
164
164
165
- const int maxAttempts = 5 ;
166
- ListResponse ? sessions = null ;
167
- for ( var attempts = 1 ; attempts <= maxAttempts ; attempts ++ )
165
+ var client = await EnsureDaemon ( ct ) ;
166
+ var sessions = await client . Synchronization . ListAsync ( new ListRequest
168
167
{
169
- ct . ThrowIfCancellationRequested ( ) ;
170
- try
168
+ Selection = new Selection
171
169
{
172
- var client = await EnsureDaemon ( ct ) ;
173
- sessions = await client . Synchronization . ListAsync ( new ListRequest
174
- {
175
- Selection = new Selection
176
- {
177
- All = true ,
178
- } ,
179
- } , cancellationToken : ct ) ;
180
- }
181
- catch ( Exception e ) when ( e is not OperationCanceledException )
182
- {
183
- if ( attempts == maxAttempts )
184
- throw ;
185
- // back off a little and try again.
186
- await Task . Delay ( 100 , ct ) ;
187
- continue ;
188
- }
189
-
190
- break ;
191
- }
170
+ All = true ,
171
+ } ,
172
+ } , cancellationToken : ct ) ;
192
173
193
174
using ( _ = await _lock . LockAsync ( ct ) )
194
175
{
@@ -211,7 +192,7 @@ public async Task Initialize(CancellationToken ct)
211
192
212
193
public async Task TerminateSyncSession ( SyncSession session , CancellationToken ct )
213
194
{
214
- if ( _sessionCount == - 1 ) throw new InvalidOperationException ( "Controller must be Initialized first" ) ;
195
+ if ( _sessionCount < 0 ) throw new InvalidOperationException ( "Controller must be Initialized first" ) ;
215
196
var client = await EnsureDaemon ( ct ) ;
216
197
// TODO: implement
217
198
@@ -272,11 +253,7 @@ private async Task<MutagenClient> EnsureDaemon(CancellationToken ct)
272
253
// </summary>
273
254
private void RemoveTransition ( Task < MutagenClient ? > transition )
274
255
{
275
- using ( _ = _lock . Lock ( ) )
276
- {
277
- ;
278
- }
279
-
256
+ using var _ = _lock . Lock ( ) ;
280
257
if ( _inProgressTransition == transition ) _inProgressTransition = null ;
281
258
}
282
259
@@ -293,9 +270,31 @@ private void RemoveTransition(Task<MutagenClient?> transition)
293
270
// Mainline; no daemon running.
294
271
}
295
272
296
- using ( _ = await _lock . LockAsync ( ct ) )
273
+ // If we get some failure while creating the log file or starting the process, we'll retry
274
+ // it up to 5 times x 100ms. Those issues should resolve themselves quickly if they are
275
+ // going to at all.
276
+ const int maxAttempts = 5 ;
277
+ ListResponse ? sessions = null ;
278
+ for ( var attempts = 1 ; attempts <= maxAttempts ; attempts ++ )
297
279
{
298
- StartDaemonProcessLocked ( ) ;
280
+ ct . ThrowIfCancellationRequested ( ) ;
281
+ try
282
+ {
283
+ using ( _ = await _lock . LockAsync ( ct ) )
284
+ {
285
+ StartDaemonProcessLocked ( ) ;
286
+ }
287
+ }
288
+ catch ( Exception e ) when ( e is not OperationCanceledException )
289
+ {
290
+ if ( attempts == maxAttempts )
291
+ throw ;
292
+ // back off a little and try again.
293
+ await Task . Delay ( 100 , ct ) ;
294
+ continue ;
295
+ }
296
+
297
+ break ;
299
298
}
300
299
301
300
return await WaitForDaemon ( ct ) ;
0 commit comments