GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ensure File#createReadStream sockets are properly closed on error by ryanseys · Pull Request #530 · googleapis/google-cloud-node

Conversation

@ryanseys

@ryanseys ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor

Trying to address #523

Don't merge this, it's not complete.

This seems to mitigate sockets staying open when a request is ended early (only scenario I tried to get the request to hang).

Question for @robertdimarco: What do you mean by:

and hang-up part-way through that file

in your comment here. I don't know how to "hang up" part way, and is it the server that is hanging up or the client? (I'm assuming client). Any other scenarios you can think of that we should test?

@stephenplusplus Seems that done at the bottom of File#createReadStream isn't called when throughStream gets an error event like you can see in this PR. I listen for this event specifically and destroy the socket related to the request at that time. This seems to destroy all the sockets laying around and fires an error events saying there is a "Download mismatch" according to verification.

My test code can be found here: https://gist.github.com/ryanseys/0e2c3244175db6525d7a

Set maxSockets: 2 when running test code because currently infinite sockets are allowed to remain open so the 4th request will succeed.

I have a feeling this is on the right track but I perhaps don't clean up everything appropriately due to the craziness that is Node.js Streams and request. In any case, it still seems to mitigate the issue a bit so far.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ryanseys
Destroy socket on throughStream error
a812561
@ryanseys ryanseys added the don't merge label May 5, 2015
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 5, 2015
@robertdimarco

robertdimarco commented May 5, 2015

Copy link
Copy Markdown
Contributor

@ryanseys I'm referring to a client disconnect before the write-stream was able to complete. We came across this issue by pointing a browser at the proxy server, let the browser connect and begin downloading, and then close the tab / refresh / etc. to cause the client to disconnect the socket. That is generally sufficient to reproduce the issue.

The handling for this I imagine is a little tricky, because the error might not be propagated from Express's write-stream to the read-stream / through-stream returned from file.createReadStream(). That part around piping likely just needs some documentation around it, as other devs will have to handle that client disconnect and propagate to this module.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor Author

The problem with using that scenario (i.e. closing a tab) is I have no idea what that means in regards to what happens to either the read or write stream. A code-only test to reproduce this is most ideal, especially for ensuring this issue doesn't arise again as a regression. That's what I'm trying to accomplish here with my test script. I will try your Express method and watch the events that occur on the streams to get an idea of where things can go wrong so we thoroughly patch this thing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robertdimarco

robertdimarco commented May 5, 2015

Copy link
Copy Markdown
Contributor

@ryanseys Understood. Let me know if I can be of any help.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented May 5, 2015

Copy link
Copy Markdown
Contributor

@ryanseys I have a bit of a different approach going on: stephenplusplus@7b4ab4f - can you try this out with your tests?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor Author

@stephenplusplus That's much cleaner and appears to work with my tests when maxSockets: Infinity (no open sockets at the end). When maxSockets: 2, weird things happen though. The third request that get's prematurely ended doesn't throw an error, or the 4th request that should succeed just never does, BUT there are no sockets left open as well. Considering we are going to have maxSockets: Infinity this shouldn't be an issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor Author

Actually that might be just because maxSockets is doing its job, in which case we just set it to Infinity and hope nobody has more than Infinity simultaneous sockets open on gcloud (but if this happens, that person should probably get a nobel prize of the node.js variety).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor Author

tl;dr: looks good to me. I'll cherry pick into this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus @ryanseys
die this way die?
f7ef2c1
@googlebot

googlebot commented May 5, 2015

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels May 5, 2015
@ryanseys

ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor Author

@googlebot confirm.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented May 5, 2015

Copy link
Copy Markdown
Contributor Author

Apparently @googlebot doesn't like you @stephenplusplus

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys ryanseys changed the title Destroy socket on throughStream error Ensure File#createReadStream sockets are properly closed on error May 5, 2015
@stephenplusplus

stephenplusplus commented May 5, 2015

Copy link
Copy Markdown
Contributor

Neither does Travis. I'm not big with robots, I guess :/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented May 14, 2015

Copy link
Copy Markdown
Contributor

@ryanseys I suppose I should fix the tests, since I'm the one who wrecked your PR!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus stephenplusplus mentioned this pull request Jun 2, 2015
storage: close sockets on error #636
Merged
1 task done
@stephenplusplus

stephenplusplus commented Jun 2, 2015

Copy link
Copy Markdown
Contributor

Carrying this on in #636.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus stephenplusplus closed this Jun 2, 2015
@ryanseys
ryanseys deleted the die-socket-die branch June 2, 2015 20:31
chingor13 pushed a commit that referenced this pull request Aug 22, 2022
@gcf-owl-bot
fix: failing tests for LRO check methods (#530)
6c543a7
feat!: *Change metadata field for the AnalyzeIamPolicyLongrunning. 
feat: Add AnalyzeMove API. feat: Add read_mask field for SearchAllResourcesRequest
feat:Add VersionedResource/AttachedResource fields for ResourceSearchResult
Committer: @alexander-fenster
PiperOrigin-RevId: 387841814
PiperOrigin-RevId: 387216202
PiperOrigin-RevId: 386530026
chingor13 pushed a commit that referenced this pull request Aug 22, 2022
@gcf-owl-bot
fix: failing tests for LRO check methods (#530)
89ee138
feat!: *Change metadata field for the AnalyzeIamPolicyLongrunning. 
feat: Add AnalyzeMove API. feat: Add read_mask field for SearchAllResourcesRequest
feat:Add VersionedResource/AttachedResource fields for ResourceSearchResult
Committer: @alexander-fenster
PiperOrigin-RevId: 387841814
PiperOrigin-RevId: 387216202
PiperOrigin-RevId: 386530026
chingor13 pushed a commit that referenced this pull request Aug 22, 2022
@gcf-owl-bot
fix: failing tests for LRO check methods (#530)
bd4baa3
feat!: *Change metadata field for the AnalyzeIamPolicyLongrunning. 
feat: Add AnalyzeMove API. feat: Add read_mask field for SearchAllResourcesRequest
feat:Add VersionedResource/AttachedResource fields for ResourceSearchResult
Committer: @alexander-fenster
PiperOrigin-RevId: 387841814
PiperOrigin-RevId: 387216202
PiperOrigin-RevId: 386530026
@sofisl sofisl mentioned this pull request Sep 15, 2022
migrate code from googleapis/nodejs-redis #3360
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Sep 15, 2022
@gcf-owl-bot
build: add generated samples to .eslintignore (#530)
14cf628
sofisl pushed a commit that referenced this pull request Sep 27, 2022
@release-please
chore: release 3.3.1 (#531)
5064d44
🤖 I have created a release \*beep\* \*boop\*
---
### [3.3.1](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v3.3.0...v3.3.1) (2021-04-19)


### Bug Fixes

* update region tag from v1beta1 to v1 for analyze-face-detection.js ([#530](https://www.github.com/googleapis/nodejs-video-intelligence/issues/530)) ([4d19f9d](https://www.github.com/googleapis/nodejs-video-intelligence/commit/4d19f9de9e386ee92ed18d9302cddc61c2dc9865))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
sofisl pushed a commit that referenced this pull request Nov 9, 2022
@release-please
chore: release 3.3.1 (#531)
2e0a07d
🤖 I have created a release \*beep\* \*boop\*
---
### [3.3.1](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v3.3.0...v3.3.1) (2021-04-19)


### Bug Fixes

* update region tag from v1beta1 to v1 for analyze-face-detection.js ([#530](https://www.github.com/googleapis/nodejs-video-intelligence/issues/530)) ([4d19f9d](https://www.github.com/googleapis/nodejs-video-intelligence/commit/4d19f9de9e386ee92ed18d9302cddc61c2dc9865))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This was referenced Jan 29, 2026
migrate code from googleapis/cloud-profiler-nodejs #7060
Closed
migrate code from googleapis/cloud-profiler-nodejs #7062
Closed
migrate code from googleapis/cloud-profiler-nodejs #7066
Closed
migrate code from googleapis/cloud-profiler-nodejs #7067
Closed
migrate code from googleapis/cloud-profiler-nodejs #7068
Closed
migrate code from googleapis/cloud-profiler-nodejs #7071
Closed
migrate code from googleapis/cloud-profiler-nodejs #7087
Merged
sofisl pushed a commit that referenced this pull request Feb 3, 2026
@renovate-bot @callmehiphop
chore(deps): update dependency eslint-plugin-node to v10 (#530)
78b5bad
This was referenced Feb 3, 2026
migrate code from googleapis/nodejs-bigquery #7111
Merged
migrate code from googleapis/nodejs-datastore #7148
Closed
sofisl pushed a commit that referenced this pull request Feb 5, 2026
@renovate-bot @callmehiphop
chore(deps): update dependency typescript to ~3.7.0 (#530)
51a72c3
GautamSharda pushed a commit that referenced this pull request Feb 5, 2026
@freelerobot
chore: add generated files bot config (#530)
1cb82fa
@GautamSharda GautamSharda mentioned this pull request Feb 5, 2026
migrate code from googleapis/nodejs-error-reporting #7169
Closed
4 tasks
@sofisl sofisl mentioned this pull request Feb 17, 2026
migrate code from googleapis/nodejs-datastore #7263
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Feb 17, 2026
@renovate-bot @callmehiphop
chore(deps): update dependency typescript to ~3.7.0 (#530)
1258848
GautamSharda pushed a commit that referenced this pull request Feb 23, 2026
@freelerobot
chore: add generated files bot config (#530)
d778b36
@GautamSharda GautamSharda mentioned this pull request Feb 23, 2026
migrate code from googleapis/nodejs-error-reporting #7294
Closed
sofisl pushed a commit that referenced this pull request Feb 24, 2026
@jkwlui @JustinBeckwith
Release v0.21.0 (#530)
3ebed73
GautamSharda pushed a commit that referenced this pull request Feb 26, 2026
@freelerobot
chore: add generated files bot config (#530)
c2119cc
@GautamSharda GautamSharda mentioned this pull request Feb 26, 2026
migrate code from googleapis/nodejs-error-reporting #7308
Merged
4 tasks
This was referenced Feb 26, 2026
migrate code from googleapis/nodejs-firestore #7311
Closed
migrate code from googleapis/nodejs-firestore #7410
Merged
GautamSharda pushed a commit that referenced this pull request Mar 5, 2026
@yoshi-automation @JustinBeckwith
chore: release 5.2.0 (#530)
8fb02e4
* updated CHANGELOG.md [ci skip]

* updated package.json [ci skip]

* updated samples/package.json [ci skip]
@GautamSharda GautamSharda mentioned this pull request Mar 5, 2026
migrate code from googleapis/nodejs-logging #7514
Merged
4 tasks
@meltsufin meltsufin mentioned this pull request Mar 10, 2026
chore: migrate code from googleapis/nodejs-logging #7550
Merged
GautamSharda pushed a commit that referenced this pull request Mar 23, 2026
@yoshi-automation @JustinBeckwith
docs: update jsdoc comments (#530)
6175fc9
@GautamSharda GautamSharda mentioned this pull request Mar 23, 2026
migrate code from googleapis/nodejs-bigtable #7852
Merged
4 tasks
GautamSharda pushed a commit that referenced this pull request Mar 25, 2026
@yoshi-automation @GautamSharda
docs: update jsdoc comments (#530)
833e8b4
shivanee-p pushed a commit that referenced this pull request Mar 27, 2026
@yoshi-automation @shivanee-p
docs: update jsdoc comments (#530)
caec43f
thiyaguk09 pushed a commit to thiyaguk09/google-cloud-node-fork that referenced this pull request May 5, 2026
@yoshi-automation @thiyaguk09
docs: update jsdoc comments (googleapis#530)
cb56e93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: no This human has *not* signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ryanseys @robertdimarco @stephenplusplus @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.