mirror of
https://github.com/denoland/deno.git
synced 2025-01-05 13:59:01 -05:00
fix race condition of _bodyWriter creation and end() call
This commit is contained in:
parent
33a852ea2b
commit
781eb00dfe
3 changed files with 9 additions and 9 deletions
|
@ -556,6 +556,7 @@ Object.defineProperties(
|
|||
if (data instanceof Buffer) {
|
||||
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
||||
}
|
||||
await this._bodyWriter.ready;
|
||||
ret = await this._bodyWriter.write(data).then(() => {
|
||||
callback?.();
|
||||
this.emit("drain");
|
||||
|
@ -587,9 +588,6 @@ Object.defineProperties(
|
|||
if (this._bodyWriter.desiredSize > 0) {
|
||||
this._bodyWriter.write(data).then(() => {
|
||||
callback?.();
|
||||
if (this.outputData.length == 0) {
|
||||
this.emit("finish");
|
||||
}
|
||||
this.emit("drain");
|
||||
}).catch((e) => {
|
||||
this._requestSendError = e;
|
||||
|
|
|
@ -678,10 +678,14 @@ class ClientRequest extends OutgoingMessage {
|
|||
}
|
||||
};
|
||||
|
||||
if (this.socket && this._bodyWriter) {
|
||||
if (this.socket && this._bodyWriter && this.outputData.length === 0) {
|
||||
finish();
|
||||
} else {
|
||||
this.on("finish", finish);
|
||||
this.on("drain", () => {
|
||||
if (this.outputData.length === 0) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
@ -998,7 +998,7 @@ Deno.test(
|
|||
request.on("close", () => {});
|
||||
request.end();
|
||||
setTimeout(() => {
|
||||
request.destroy(new Error());
|
||||
request.destroy();
|
||||
resolve();
|
||||
}, 100);
|
||||
|
||||
|
@ -1463,9 +1463,7 @@ Deno.test(
|
|||
},
|
||||
);
|
||||
|
||||
Deno.test("[node/http] http.request() post streaming body works", {
|
||||
ignore: true,
|
||||
}, async () => {
|
||||
Deno.test("[node/http] http.request() post streaming body works", async () => {
|
||||
const server = http.createServer((req, res) => {
|
||||
if (req.method === "POST") {
|
||||
let receivedBytes = 0;
|
||||
|
|
Loading…
Reference in a new issue