1
0
Fork 0
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:
Yoshiya Hinosawa 2024-10-17 22:12:07 +09:00
parent 33a852ea2b
commit 781eb00dfe
No known key found for this signature in database
GPG key ID: 9017DB4559488785
3 changed files with 9 additions and 9 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;