-
-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload stream fires "data" after "end" #131
Comments
Hey @juona, thank you so much for the fantastic details here. I have a suspicion here, and I will probably have some time later this afternoon to investigate further. I’ll comment back once I have more details. |
I'm pretty sure the right event to listen for when handling file upload streams in resolvers is |
Well, it depends if you have the listener after piping to a writable stream or not. |
Hey, Thank you for your responses! @jaydenseric @mike-marcacci thanks, I hope this does not turn into a big waste of time! |
A bit more information, if that helps. If I pipe the stream and use const stream = file.createReadStream();
stream.pause();
setTimeout(() => {
stream.pipe(
through(
function() {
logger.info("DATA"); // <-- this will not be logged
},
function() {
logger.info("END"); // <-- this WILL be logged
resolve();
}
)
);
stream.pause();
}, 1000); |
OK, I got a moment to track down some stuff here. Before I go any further, I want to make sure you are talking about Assuming this is Despite many attempts, I couldn't get the same kind of behavior you're talking about. However, I'm going to remove this special behavior from Thanks again for all the great investigation prior to posting an issue. EDIT: I'm going to make this change regardless, because these features were more a convenience for me, and aren't necessary. But if you want to test my theory against your codebase, remove this and this in your |
Hey @mike-marcacci, I believe I roughly understand your explanation (I don't know the internals of fs-capacitor or what it's for even), but I do know for sure that your fix works! : ] well done and thank you very much for this. I am using the fix branch for now hoping that a new release of graphql-upload comes soon. |
@juona it's on the way, give me a few minutes 🚀 |
Update fs-capacitor and corresponding tests, fixes #131 .
The fix is published in v8.0.4! |
When running the populate script, I was getting an ERR_STREAM_WRITE_AFTER_END error each time. It seems related to jaydenseric/graphql-upload#131 but unfortunately this is a transitive dependency of apollo-server-express and I can't directly upgrade to the latest version of graphql-upload. This work-around seems to fix things though.
Update fs-capacitor and corresponding tests, fixes jaydenseric/graphql-upload#131 .
Hi again,
Node v10.14.1, graphql-upload v8.0.3.
An odd one here, possibly not a bug, might also be a mistake on my side. Either way, would appreciate your advice! : ]
First, simplified example code. I use this code to upload a file to my GraphQL server. The type of
input.icon
is Upload.The call to
setTimeout
simulates certain asynchronous logic present in my code. I perform an asynchronous call somewhere in the program, wait for a response, and only then I pipe the upload stream to where I want it to go.This code works fine and prints Receiving data a number of times and finishes with Stream ended. However, there is a condition when this does not work:
readableHighWaterMark
."end"
event handler is literally attached before the data handler, like this:In this case, the code will print Stream ended first, and then Receiving data.
Some more notes:
const stream = fs.createReadStream("/home/juona/ex.tar.bz2");
to read the same file from the local file system, instead of uploading it viaconst stream = file.createReadStream();
, it works just fine.stream.pause()
beforesetTimeout
and thenstream.resume()
anywhere in the timeout callback fixes the problem.setTimeout
is removed or if the timeout is very low (e.g. if I useprocess.nextTick()
instead), regardless of the order of event handler attachment. I would assume that the timeout has to be longer than the time it takes to upload the file.I am having trouble understanding what is happening here. In the actual application I use a bunch of other stream libraries to transform the upload and one of them fails because it expects
stream.end
to be called after at at least onestream.write
, which I guess is a fair expectation. Also the problem is more complex in the real scenario sincestream.pause()
does not really help in that case, but I have to start the investigation somewhere...Could perhaps be an issue in Node itself or a compatibility problem, but since it matters whether or not I use the upload stream or a different one, I am coming to you first.
Any thoughts?
The text was updated successfully, but these errors were encountered: