{"action":"reopened","issue":{"url":"https://api.github.com/repos/google/google-api-dotnet-client/issues/592","labels_url":"https://api.github.com/repos/google/google-api-dotnet-client/issues/592/labels{/name}","comments_url":"https://api.github.com/repos/google/google-api-dotnet-client/issues/592/comments","events_url":"https://api.github.com/repos/google/google-api-dotnet-client/issues/592/events","html_url":"https://github.com/google/google-api-dotnet-client/issues/592","id":104275454,"number":592,"title":"abstract class BaseClientService supposed to be thread-safe, but is not","user":{"login":"geroj","id":5442228,"avatar_url":"https://avatars.githubusercontent.com/u/5442228?v=3","gravatar_id":"","url":"https://api.github.com/users/geroj","html_url":"https://github.com/geroj","followers_url":"https://api.github.com/users/geroj/followers","following_url":"https://api.github.com/users/geroj/following{/other_user}","gists_url":"https://api.github.com/users/geroj/gists{/gist_id}","starred_url":"https://api.github.com/users/geroj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geroj/subscriptions","organizations_url":"https://api.github.com/users/geroj/orgs","repos_url":"https://api.github.com/users/geroj/repos","events_url":"https://api.github.com/users/geroj/events{/privacy}","received_events_url":"https://api.github.com/users/geroj/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/google-api-dotnet-client/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/google/google-api-dotnet-client/milestones/3","html_url":"https://github.com/google/google-api-dotnet-client/milestones/1.10","labels_url":"https://api.github.com/repos/google/google-api-dotnet-client/milestones/3/labels","id":1369383,"number":3,"title":"1.10","description":null,"creator":{"login":"peleyal","id":3082873,"avatar_url":"https://avatars.githubusercontent.com/u/3082873?v=3","gravatar_id":"","url":"https://api.github.com/users/peleyal","html_url":"https://github.com/peleyal","followers_url":"https://api.github.com/users/peleyal/followers","following_url":"https://api.github.com/users/peleyal/following{/other_user}","gists_url":"https://api.github.com/users/peleyal/gists{/gist_id}","starred_url":"https://api.github.com/users/peleyal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peleyal/subscriptions","organizations_url":"https://api.github.com/users/peleyal/orgs","repos_url":"https://api.github.com/users/peleyal/repos","events_url":"https://api.github.com/users/peleyal/events{/privacy}","received_events_url":"https://api.github.com/users/peleyal/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":10,"state":"open","created_at":"2015-10-21T22:45:37Z","updated_at":"2015-11-12T20:00:52Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-09-01T14:11:57Z","updated_at":"2015-11-12T20:00:52Z","closed_at":null,"body":"short description:\r\n==============\r\nBaseClientService expose List Service.HttpClient.MessageHandler.ExceptionHandlers.Add(this);\r\nThis list can be accessed from several threads and cause application to crash.\r\n\r\nlong description:\r\n=============\r\nI got several exceptions, when I used InsertMediaUpload request from namespace Google.Apis.Storage.v1 from multiple threads.\r\n\r\nThis class implements ResumableUpload<TRequest>, where entire upload is done. \r\n\r\nEach exception was found in calling method UploadCoreAsync:\r\n\r\n```\r\nObject reference not set to an instance of an object.\r\n   at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)\r\n   at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n   at Google.Apis.Upload.ResumableUpload`1.<UploadCoreAsync>d__e.MoveNext() in c:\\code\\google.com\\google-api-dotnet-client\\default\\Tools\\Google.Apis.Release\\bin\\Debug\\test\\default\\Src\\GoogleApis\\Apis\\[Media]\\Upload\\ResumableUpload.cs:l\r\nine 459\r\n```\r\n\r\nor\r\n\r\n```\r\nCollection was modified; enumeration operation may not execute.\r\n   at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)\r\n   at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n   at Google.Apis.Upload.ResumableUpload`1.<UploadCoreAsync>d__e.MoveNext() in c:\\code\\google.com\\google-api-dotnet-client\\default\\Tools\\Google.Apis.Release\\bin\\Debug\\test\\default\\Src\\GoogleApis\\Apis\\[Media]\\Upload\\ResumableUpload.cs:line 459\r\nMicrosoft.Threading.Tasks\r\n```\r\n\r\nor\r\n\r\n```\r\nIndex was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index\r\n   at System.Collections.Generic.List`1.RemoveAt(Int32 index)\r\n   at System.Collections.Generic.List`1.Remove(T item)\r\n   at Google.Apis.Upload.ResumableUpload`1.ServerErrorCallback.Dispose() in c:\\code\\google.com\\google-api-dotnet-client\\default\\Tools\\Google.Apis.Release\\bin\\Debug\\test\\default\\Src\\GoogleApis\\Apis\\[Media]\\Upload\\ResumableUpload.cs:line 273\r\n   at Google.Apis.Upload.ResumableUpload`1.<UploadCoreAsync>d__e.MoveNext() in c:\\code\\google.com\\google-api-dotnet-client\\default\\Tools\\Google.Apis.Release\\bin\\Debug\\test\\default\\Src\\GoogleApis\\Apis\\[Media]\\Upload\\ResumableUpload.cs:line 463\r\nmscorlib\r\n```\r\n\r\nProblem is in this part of code(method UploadCoreAsync) :\r\nusing (var callback = new ServerErrorCallback(this))\r\n                {\r\n                }\r\n\r\nServerErrorCallback is working with List ExceptionHandlers exposed by BaseClientService\r\nOwner.Service.HttpClient.MessageHandler.UnsuccessfulResponseHandlers.Add(this);\r\nOwner.Service.HttpClient.MessageHandler.ExceptionHandlers.Add(this);\r\n\r\nInternal implementation (ConfigurableMessageHandler) is using List, so when I called code in UploadCoreAsync from several threads, it caused List to crash.\r\n"}}