Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved: Change tracker will retry connection if closed by proxy

Tweak the heuristic added in 6043f1c by looking at total connection time, not idle time.
  • Loading branch information...
commit 92a6edb94805ccffecc582fa8b37fe4ae6954772 1 parent fced3bb
@snej snej authored
View
2  Source/ChangeTracker/TDConnectionChangeTracker.h
@@ -17,7 +17,7 @@
NSURLConnection* _connection;
NSMutableData* _inputBuffer;
unsigned _retryCount;
- CFAbsoluteTime _lastDataTime;
+ CFAbsoluteTime _startTime;
}
@end
View
11 Source/ChangeTracker/TDConnectionChangeTracker.m
@@ -40,6 +40,7 @@ - (BOOL) start {
}];
_connection = [[NSURLConnection connectionWithRequest: request delegate: self] retain];
+ _startTime = CFAbsoluteTimeGetCurrent();
LogTo(ChangeTracker, @"%@: Started... <%@>", self, request.URL);
return YES;
}
@@ -50,7 +51,6 @@ - (void) clearConnection {
_connection = nil;
[_inputBuffer release];
_inputBuffer = nil;
- _lastDataTime = 0;
}
@@ -83,7 +83,6 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
LogTo(ChangeTrackerVerbose, @"%@: Got %lu bytes", self, (unsigned long)data.length);
- _lastDataTime = CFAbsoluteTimeGetCurrent();
[_inputBuffer appendData: data];
}
@@ -115,10 +114,10 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
dataUsingEncoding: NSUTF8StringEncoding]]) {
// Looks like the connection got closed by a proxy (like AWS' load balancer) before
// the server had an actual change to send.
- NSTimeInterval idle = CFAbsoluteTimeGetCurrent() - _lastDataTime;
- Warn(@"%@: Connection closed (by proxy?) after %.1f sec idle", self, idle);
- if (idle >= 30.0 && idle < _heartbeat) {
- self.heartbeat = idle * 0.75;
+ NSTimeInterval elapsed = CFAbsoluteTimeGetCurrent() - _startTime;
+ Warn(@"%@: Longpoll connection closed (by proxy?) after %.1f sec", self, elapsed);
+ if (elapsed >= 30.0 && elapsed < _heartbeat) {
+ self.heartbeat = elapsed * 0.75;
restart = YES;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.