-
-
Notifications
You must be signed in to change notification settings - Fork 938
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
Fix for sending files with size 0
on stat
#1488
Conversation
This issue made me realize that we might have a TOCTOU problem. This code simulate what Got does, but one step at a time. const fs = require('fs');
const http = require('http');
const stream = require('stream');
fs.writeFileSync('test.txt', 'TEST');
const readStream = fs.createReadStream('test.txt');
const { size: sizeBefore } = fs.statSync('test.txt');
console.log('Size before', sizeBefore);
const request = http.request({
host: '127.0.0.1',
port: '8080',
headers: {
'content-length': sizeBefore,
},
});
fs.writeFileSync('test.txt', 'FILE CHANGED'); // Something (not Got) write the file
const { size: sizeAfter } = fs.statSync('test.txt');
console.log('Size after', sizeAfter);
stream.pipeline(readStream, request, (err) => {
console.log('Ended');
console.error('Error', err);
}); The result is
Request made to the server:
The I don't think we should care about this, it should be the user that must not write to the file while reading it. The example before has a 100% success rate, with Got it become more difficult to replicate (but it's still possible). Examples from Got (inserting code in specific places and praying the scheduler for cooperation):
|
This is a completely valid argument and I agree with you 100%. |
So why we don't just remove the |
Because it's going to break the upload progress function. Actually we can use This is a solution if the "problem mentioned" was the PR itself.
the file can be modified even while reading, so the user has to be fully responsible for that. |
But that will be only for files. People can provide their own |
Sure, but if we can still automate the upload progress on the file that supports it (the ones without size != 0) it would be great. |
Mouse slipped on "Close"... BTW I think we can still use
|
@Giotino I'd just read the |
Ok, but I think there's someone out there that use the upload progress feature on files (as it's documented). |
But we're already developing Got 12 in the master branch, don't we? |
Since we don't know how much time is gonna take to release Got 12 I would like to be able to publish little fix like this to Got 11. I think that until Got 12 is finally released we should still patch Got 11, at least when the fix is not huge and/or breaking. |
/cc @sindresorhus |
@Giotino I generally agree, but doing it this way has a tendency to just delay the major version for a long time (there's always going to be "just one more fix"). I think it's better to commit the proper breaking change to |
Actually, since there are still no breaking changes on master, I guess we can just merge this in and do a minor release. @Giotino Can you open an issue or PR about the breaking change? |
Ah, I know why it worked on Got 10 alpha but not Got 10 beta: got/source/request-as-event-emitter.ts Line 394 in 72390c2
See |
Checklist
Fixes #1486