{"action":"created","issue":{"url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk/issues/34","repository_url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk","labels_url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk/issues/34/comments","events_url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk/issues/34/events","html_url":"https://github.com/aliyun/aliyun-oss-ios-sdk/issues/34","id":173752398,"number":34,"title":"同一 client 进行多次不同的 HEAD 请求，会遗失部分调用回调","user":{"login":"beimen","id":1940699,"avatar_url":"https://avatars.githubusercontent.com/u/1940699?v=3","gravatar_id":"","url":"https://api.github.com/users/beimen","html_url":"https://github.com/beimen","followers_url":"https://api.github.com/users/beimen/followers","following_url":"https://api.github.com/users/beimen/following{/other_user}","gists_url":"https://api.github.com/users/beimen/gists{/gist_id}","starred_url":"https://api.github.com/users/beimen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beimen/subscriptions","organizations_url":"https://api.github.com/users/beimen/orgs","repos_url":"https://api.github.com/users/beimen/repos","events_url":"https://api.github.com/users/beimen/events{/privacy}","received_events_url":"https://api.github.com/users/beimen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-29T11:21:59Z","updated_at":"2016-10-24T07:08:17Z","closed_at":"2016-10-24T07:08:17Z","body":"0.如题，根据文档方法，使用 HEAD 方法判断文件是否存在： https://help.aliyun.com/document_detail/32064.html?spm=5176.doc32061.6.354.ST0hpM \r\n\r\n1.client 生成方法\r\n```\r\n+ (OSSClient *)clientWithEndPoint:(NSString *)endPoint {\r\n\tstatic NSMutableDictionary<NSString *, OSSClient *> *clients;\r\n\tstatic dispatch_once_t onceToken;\r\n\tdispatch_once(&onceToken, ^{\r\n\t\tclients = [NSMutableDictionary new];\r\n\t});\r\n\tOSSClient *client = clients[endPoint];\r\n\tif (client == nil) {\r\n\t\tOSSClientConfiguration *conf = [OSSClientConfiguration new];\r\n\t\tconf.maxRetryCount = 2;\r\n\t\tconf.timeoutIntervalForRequest = 30;\r\n\t\tconf.timeoutIntervalForResource = 24 * 60 * 60;\r\n\t\t\r\n\t\tclient = [[OSSClient alloc] initWithEndpoint:endPoint credentialProvider:self.stsCredential clientConfiguration:conf];\r\n\t\t[clients setObject:client forKey:endPoint];\r\n\t}\r\n\t\r\n\treturn client;\r\n}\r\n```\r\n\r\n2.访问控制的方式是 FederationToken\r\n```\r\nstatic id<OSSCredentialProvider> stsCredential;\r\nstatic dispatch_semaphore_t stsRequestSemaphore;\r\n+ (id<OSSCredentialProvider>)stsCredential {\r\n\tif (stsCredential == nil) {\r\n\t\tstatic dispatch_once_t onceToken;\r\n\t\tdispatch_once(&onceToken, ^{\r\n\t\t\tstsRequestSemaphore = dispatch_semaphore_create(0);\r\n\t\t\tstsCredential = [[OSSFederationCredentialProvider alloc] initWithFederationTokenGetter:^OSSFederationToken *{\r\n\t\t\t\tWBAlicloudTokenRequestModel *requestModel = [WBAlicloudTokenRequestModel new];\r\n\t\t\t\tDKDataManager *dataManager = [DKDataManager new];\r\n\t\t\t\tOSSFederationToken *resultToken = [OSSFederationToken new];\r\n\t\t\t\t[dataManager requestWithRequestModel:requestModel completedBlock:^(DKResponseModel *responseModel, NSError *error) {\r\n\t\t\t\t\tif (error == nil) {\r\n\t\t\t\t\t\tWBAlicloudTokenResponseModel *response = (WBAlicloudTokenResponseModel *)responseModel;\r\n\t\t\t\t\t\tresultToken.tAccessKey = response.AccessKeyId;\r\n\t\t\t\t\t\tresultToken.tSecretKey = response.AccessKeySecret;\r\n\t\t\t\t\t\tresultToken.tToken = response.SecurityToken;\r\n\t\t\t\t\t\tresultToken.expirationTimeInGMTFormat = response.Expiration;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdispatch_semaphore_signal(stsRequestSemaphore);\r\n\t\t\t\t}];\r\n\t\t\t\tdispatch_semaphore_wait(stsRequestSemaphore, DISPATCH_TIME_FOREVER);\r\n\t\t\t\treturn resultToken;\r\n\t\t\t}];\r\n\t\t});\r\n\t}\r\n\t\r\n\treturn stsCredential;\r\n}\r\n```\r\n\r\n3.连续做 20 次 HEAD 方法\r\n```\r\nNSLog(@\"FLAG 1\");\r\n[headTask continueWithBlock:^id(OSSTask *task) {\r\n    NSLog(@\"FLAG 2\");\r\n    NSLog(@\"%@\", task.error);\r\n    return nil;\r\n}];\r\n```\r\n会发现 FLAG 1 打印次数有很大概率比 FLAG 2 多。\r\n\r\n4.OSS_IOS_SDK_VERSION 2.5.1\r\n\r\n不太明白是不是自己的操作哪里有问题。"},"comment":{"url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk/issues/comments/255663826","html_url":"https://github.com/aliyun/aliyun-oss-ios-sdk/issues/34#issuecomment-255663826","issue_url":"https://api.github.com/repos/aliyun/aliyun-oss-ios-sdk/issues/34","id":255663826,"user":{"login":"beimen","id":1940699,"avatar_url":"https://avatars.githubusercontent.com/u/1940699?v=3","gravatar_id":"","url":"https://api.github.com/users/beimen","html_url":"https://github.com/beimen","followers_url":"https://api.github.com/users/beimen/followers","following_url":"https://api.github.com/users/beimen/following{/other_user}","gists_url":"https://api.github.com/users/beimen/gists{/gist_id}","starred_url":"https://api.github.com/users/beimen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beimen/subscriptions","organizations_url":"https://api.github.com/users/beimen/orgs","repos_url":"https://api.github.com/users/beimen/repos","events_url":"https://api.github.com/users/beimen/events{/privacy}","received_events_url":"https://api.github.com/users/beimen/received_events","type":"User","site_admin":false},"created_at":"2016-10-24T07:08:17Z","updated_at":"2016-10-24T07:08:17Z","body":"研究了下，应该是之前代码写得有问题，不是 SDK 的问题。故而关闭。"}}
{"actor":{"display_login":"beimen"}}