Threading issue
Closed this issue · 5 comments
Description:
I have three controllers. The first is a tweaked version of AVCAM offered by Apple that involves using the AVFramework to create a custom photo/video capture controller, a controller that allows a user to annotate a photo/video and then another controller that I display once this annotating is done. The controller flow is done in this order, with a user capturing the content, annotating, and then displaying this last controller.
The issue the arises when either transitioning from the mark up to the last view controller or progressively dismissing the stack (i.e. dismissing the last controller, loading the view from the annotate controller that contains the s3 code and then dismissing this to return to the first (camera) controller). I perform a putobject request on the mark up (2nd in stack) controller. This has been working well until recently when I encounter this issue:
This does not crash all threads, as my camera controller preview layer is still reading a buffer. However, the main thread seems to halt as no more selectors or actions can be received. I know v2 is out and I should be developing with that but I need a working app now. This seems to just be something to do with the way aws threads the upload response handlers so I am seeking on advice on how to do this. For reference I only have didcompleteWithResponse: delegate method written and not didSendBodyData:.
If you need something now, I’d skip the TransferManager and the broken delegate methods and use something like this instead:
-(void) uploadData:(NSData_)data toBucket:(NSString_)bucket withKey:(NSString*)key {
typeof(self) weakSelf = self;
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(aQueue, ^{
typeof(self) strongSelf = weakSelf;
S3PutObjectRequest * request = [[S3PutObjectRequest alloc] initWithKey:key inBucket:bucket];
[request setData:data];
S3PutObjectResponse *response = nil;
int attempts = 0;
do {
response = [[AmazonClientManager s3] putObject:request];
attempts++;
} while (response.error && attempts<retries);
//Let the UI thread know what happened with the upload
dispatch_async(dispatch_get_main_queue(),^(void) {
[strongSelf uploadDidCompleteWithSuccess:response.error = nil];
});
});
}
-(void)uploadDidCompleteWithSuccess:(bool)success {
//Handle the upload result
}
On Jul 28, 2014, at 3:19 PM, undiscovrd notifications@github.com wrote:
Description:
I have three controllers. The first is a tweaked version of AVCAM offered by Apple that involves using the AVFramework to create a custom photo/video capture controller, a controller that allows a user to annotate a photo/video and then another controller that I display once this annotating is done. The controller flow is done in this order, with a user capturing the content, annotating, and then displaying this last controller.
The issue the arises when either transitioning from the mark up to the last view controller or progressively dismissing the stack (i.e. dismissing the last controller, loading the view from the annotate controller that contains the s3 code and then dismissing this to return to the first (camera) controller). I perform a putobject request on the mark up (2nd in stack) controller. This has been working well until recently when I encounter this issue:
This does not crash all threads, as my camera controller preview layer is still reading a buffer. However, the main thread seems to halt as no more selectors or actions can be received. I know v2 is out and I should be developing with that but I need a working app now. This seems to just be something to do with the way aws threads the upload response handlers so I am seeking on advice on how to do this. For reference I only have didcompleteWithResponse: delegate method written and not didSendBodyData:.
—
Reply to this email directly or view it on GitHub.
I realize what's happening: the didSendBodyData: delegate method gets stuck mid-upload
@middleseatman thanks I will try this out!
Hello all, So I did some more debugging and I perform two upload requests, one right after the other. It appears that they are sent to a separate queue. The delegate methods are called on the main thread when there is an update on the separate thread it seems. I figure this because I can still perform UI actions on the main thread while the upload is in progress. I also found out that a lengthy content upload causes an issue as the state of the view controller changes drastically by the time a delegate method is called on the main thread from the s3's queue.
BTW, my other account is @undiscovrd
The TransferManager was rewritten in v2 of the SDK, please report any issues in that repo (https://github.com/aws/aws-sdk-ios).