0

When running Google.Cloud.Storage.V1 nuget package to upload file to Google Storage behind company's firewall, it hits exception "unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.".

source: VMScaleSet windows VMs
destination: GCS
Nuget package: Google.Cloud.Storage.V1     2.3.0

Here is c# code, to upload local file to GCS.

StorageClient.Create().UploadObject(bucketName, objectName, null, stream);

Authentication has been set up following this guide https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-csharp

Everything works fine on local machine and on-premises serves in company. But does not work on Azure VMScaleSet VM. Firewall rule has been implemented between VMScaleSet and www.googleapis.com port 443. Azure VM is able to telnet www.googleapis.com 443

What else could be missing to establish connection?

Please help.

System.Net.Http.HttpRequestException: An error occurred while sending the 
request. ---> System.Net.WebException: The underlying connection was 
closed: An unexpected error occurred on a send. ---> 
System.IO.IOException: Unable to read data from the transport connection: 
An existing connection was forcibly closed by the remote host. ---> 
System.Net.Sockets.SocketException: An existing connection was forcibly 
closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult 
asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.CheckFinalProgress() in T:\src\github\google-cloud-dotnet\releasebuild\apis\Google.Cloud.Storage.V1\Google.Cloud.Storage.V1\StorageClientImpl.UploadObject.cs:line 202
   at Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.Execute() in T:\src\github\google-cloud-dotnet\releasebuild\apis\Google.Cloud.Storage.V1\Google.Cloud.Storage.V1\StorageClientImpl.UploadObject.cs:line 154
   at Google.Cloud.Storage.V1.StorageClientImpl.UploadObject(String bucket, String objectName, String contentType, Stream source, UploadObjectOptions options, IProgress`1 progress) in T:\src\github\google-cloud-dotnet\releasebuild\apis\Google.Cloud.Storage.V1\Google.Cloud.Storage.V1\StorageClientImpl.UploadObject.cs:line 70
George Chen
  • 13,703
  • 2
  • 11
  • 26
  • I could not find any relevant guide on how to connect VMScaleSet Windows VMs to GCS. However, I found this [guide](https://cloud.google.com/compute/docs/disks/gcs-buckets) which explains how to connect a Google Compute Engine VM to GCS. Perhaps, following the same steps may help. Moreover, I do realize that for other produts such as Cloud SQL, you can [connect an external application to Cloud SQL](https://cloud.google.com/sql/docs/mysql/connect-external-app) by using different methods. The error you are getting is broad since it can be due to network issues (Firewall), or connection timeouts. – sllopis Nov 06 '19 at 14:52
  • There is a similar question https://stackoverflow.com/questions/55967800/upload-files-to-google-cloud-storage-using-c-sharp. His code throw exception "task has been cancelled" at same line of code. Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.CheckFinalProgress(), He said his issue was port 80 and 443 were blocked. I did open 443, maybe I need open 80. – user3191941 Nov 08 '19 at 01:42
  • Sure, keep me posted. – sllopis Nov 08 '19 at 14:35

0 Answers0