Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WriteChannel for GCS doesn't read response body, leaks connections #4107

@bobveznat

Description

@bobveznat

Environment details

  • OS: linux / centos7
  • Java version: 1.9
  • google-cloud-java version(s):
    • com.google.cloud:google-cloud-storage:1.52.0
    • com.google.cloud:google-cloud-core-http:1.52.0
    • org.apache.httpcomponents:httpclient:4.5.5

Steps to reproduce

At a high level we're trying to upload 100s of objects to GCS ~quickly. We want to do this using an Apache HTTP client because we need to use a custom resolver. That said, I think this is broken on both Apache and other http clients, it just may not manifest itself the same way.

  1. Use a custom transport factory builder in order to use Apache HTTP Client
  2. Allocate a PoolingHttpClientConnectionManager in your transport, set the pool size to 1
  3. Instantiate the Storage service using this transport factory
  4. Allocate a write channel
  5. Write to it
  6. Close it
  7. Allocate another write channel
  8. Try to write to it.

Under the hood the client will try to find an available connection from the pool and fail. It thinks the one we used earlier is still in use.

If you run ss or netstat on the machine at this point you can see an established connection to GCS with ~165 bytes sitting in the socket's receive buffer.

The reason is that we don't read the body of the response. See here:

https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java#L685

The response in both success and exception cases is discarded without ever reading or closing the response.

HttpRequest's execute() method pretty clearly states we need to do something with the response:

https://developers.google.com/api-client-library/java/google-http-java-client/reference/1.20.0/com/google/api/client/http/HttpRequest#execute()

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions