Skip to content

Commit c7ceedd

Browse files
authored
fix: putStream can not close request when stream destroyed (#782)
1 parent b4d1c56 commit c7ceedd

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/object.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const mime = require('mime');
1010
const callback = require('./common/callback');
1111
const signHelper = require('./common/signUtils');
1212
const { Transform } = require('stream');
13+
const pump = require('pump');
1314

1415
const proto = exports;
1516

@@ -129,7 +130,7 @@ proto.putStream = async function putStream(name, stream, options) {
129130
this.push(chunk);
130131
done();
131132
};
132-
params.stream = stream.pipe(transform);
133+
params.stream = pump(stream, transform);
133134
params.successStatuses = [200];
134135

135136
const result = await this.request(params);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"mime": "^2.4.5",
129129
"mz-modules": "^2.1.0",
130130
"platform": "^1.3.1",
131+
"pump": "^3.0.0",
131132
"sdk-base": "^2.0.1",
132133
"stream-http": "2.8.2",
133134
"stream-wormhole": "^1.0.4",

test/node/object.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ describe('test/object.test.js', () => {
159159
assert.equal(r.content.length, buf.length);
160160
assert.deepEqual(r.content, buf);
161161
});
162+
163+
it('should throw error with stream destroy', async () => {
164+
const name = `${prefix}ali-sdk/oss/putStream-source-destroy.js`;
165+
try {
166+
const readerStream = fs.createReadStream(__filename);
167+
168+
readerStream.on('data', () => {
169+
readerStream.destroy();
170+
});
171+
await store.putStream(name, readerStream);
172+
} catch (error) {
173+
assert.strictEqual(error.status, -1);
174+
}
175+
});
162176
});
163177

164178
describe('processObjectSave()', () => {

0 commit comments

Comments
 (0)