Skip to content

Commit

Permalink
fix: putStream can not close request when stream destroyed (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyie authored Jun 4, 2020
1 parent b4d1c56 commit c7ceedd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mime = require('mime');
const callback = require('./common/callback');
const signHelper = require('./common/signUtils');
const { Transform } = require('stream');
const pump = require('pump');

const proto = exports;

Expand Down Expand Up @@ -129,7 +130,7 @@ proto.putStream = async function putStream(name, stream, options) {
this.push(chunk);
done();
};
params.stream = stream.pipe(transform);
params.stream = pump(stream, transform);
params.successStatuses = [200];

const result = await this.request(params);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"mime": "^2.4.5",
"mz-modules": "^2.1.0",
"platform": "^1.3.1",
"pump": "^3.0.0",
"sdk-base": "^2.0.1",
"stream-http": "2.8.2",
"stream-wormhole": "^1.0.4",
Expand Down
14 changes: 14 additions & 0 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ describe('test/object.test.js', () => {
assert.equal(r.content.length, buf.length);
assert.deepEqual(r.content, buf);
});

it('should throw error with stream destroy', async () => {
const name = `${prefix}ali-sdk/oss/putStream-source-destroy.js`;
try {
const readerStream = fs.createReadStream(__filename);

readerStream.on('data', () => {
readerStream.destroy();
});
await store.putStream(name, readerStream);
} catch (error) {
assert.strictEqual(error.status, -1);
}
});
});

describe('processObjectSave()', () => {
Expand Down

0 comments on commit c7ceedd

Please sign in to comment.