Skip to content

Conversation

@ryanseys
Copy link
Contributor

@ryanseys ryanseys commented Mar 4, 2015

I (think I) have a fix here for #422 but writing the test for it has been troublesome for me, most likely due to my lack of understanding with streams. Hopefully @stephenplusplus can help!

The test is passing (all asserts pass and done is called) and then immediately failing due to stream.end being called on a stream that (I guess) no longer exists?

I'm getting the following error when running the test included in this PR and don't know how to fix:

> mocha test/*

  File
    createWriteStream
      ✓ should re-emit errors
      1) should re-emit errors

  1 passing (23ms)
  1 failing

  1) File createWriteStream should re-emit errors:
     Uncaught TypeError: Cannot read property 'ending' of undefined
      at Duplexify.end (/Users/ryanseys/gcloud-node/node_modules/duplexify/index.js:218:27)
      at handleError (/Users/ryanseys/gcloud-node/lib/storage/file.js:1064:12)
      at DestroyableTransform.<anonymous> (/Users/ryanseys/gcloud-node/lib/storage/file.js:992:7)
      at DestroyableTransform.emit (events.js:129:20)
      at Immediate._onImmediate (/Users/ryanseys/gcloud-node/test/storage/file.js:553:18)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 4, 2015

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

I believe handleError doesn't need to end the stream. Errors are emitted back to the stream that was passed into startResumableUpload_, which ends the stream there.

... streams of tears.

This comment was marked as spam.

@ryanseys
Copy link
Contributor Author

ryanseys commented Mar 5, 2015

PTAL 😄

stephenplusplus added a commit that referenced this pull request Mar 5, 2015
Emit errors from upstream on file upload
@stephenplusplus stephenplusplus merged commit 751d97f into googleapis:master Mar 5, 2015
@stephenplusplus
Copy link
Contributor

👍

@teddybearz
Copy link

Is it possible that handleError() being called twice? i.e. one error event and one complete event with error come back to back?

@ryanseys
Copy link
Contributor Author

ryanseys commented Mar 5, 2015

It was that the stream was being closed too many times. I believe we have addressed this issue fully. If you want to test against master, that would be wonderful!

@teddybearz
Copy link

I wonder in real network scenario (not just the test mock environment), it is possible that there will be one error event and one complete event+error being emitted back to back with error code all equals to 404 or 499-600. If it happens, the handleError() will be called twice and startUpload() resumeUpload() will be called twice.

@stephenplusplus
Copy link
Contributor

The write stream will either emit an error or complete, it can't do both.

Regardless, somewhat related, we should aim to "once-ify" our user provided callbacks.

@stephenplusplus
Copy link
Contributor

@teddybearz I can't help but feel I'm missing your point. If I am, thanks for your patience.

@teddybearz
Copy link

The write stream will either emit an error or complete, it can't do both.
In theory yes, but for event driven code, it takes some efforts to enforce and maintain that. Maybe better not assume too much and prepare for the worst.

BTW, is there a mock environment I can use to test my code that uses this library? So I can simulate bad-upload/bad-download/network-connection-reset those kinds of error cases programmatically? I am tired of pulling cable now 😄

@ryanseys
Copy link
Contributor Author

ryanseys commented Mar 7, 2015

@teddybearz You might have some luck trying out https://github.com/tylertreat/Comcast 😄

chingor13 pushed a commit that referenced this pull request Aug 22, 2022
sofisl pushed a commit that referenced this pull request Sep 15, 2022
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/b742586e-df31-4aac-8092-78288e9ea8e7/targets

- [ ] To automatically regenerate this PR, check this box.

PiperOrigin-RevId: 325949033
Source-Link: googleapis/googleapis@94006b3
sofisl pushed a commit that referenced this pull request Sep 27, 2022
sofisl pushed a commit that referenced this pull request Oct 12, 2022
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/dfbad313-7afb-4cf6-b229-0476fcc2130c/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@57c23fa
sofisl pushed a commit that referenced this pull request Oct 13, 2022
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/dfbad313-7afb-4cf6-b229-0476fcc2130c/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@57c23fa
sofisl pushed a commit that referenced this pull request Nov 11, 2022
sofisl pushed a commit that referenced this pull request Nov 17, 2022
sofisl pushed a commit that referenced this pull request Jan 27, 2026
The native bindings have been moved to the pprof module. This module
can be pure-JS now.
sofisl pushed a commit that referenced this pull request Jan 27, 2026
The native bindings have been moved to the pprof module. This module
can be pure-JS now.
sofisl pushed a commit that referenced this pull request Jan 28, 2026
The native bindings have been moved to the pprof module. This module
can be pure-JS now.
miguelvelezsa pushed a commit that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants