aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-08-06 19:30:06 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-06 19:30:06 -0700
commit70c3371b14293e18a5e0470e8b8cd4c04259a606 (patch)
treef17edb695a4c8461bb1b25f302f180843a84a1e7
parent0b2be88bac4301df22528f3e032026df5b512887 (diff)
downloadbun-70c3371b14293e18a5e0470e8b8cd4c04259a606.tar.gz
bun-70c3371b14293e18a5e0470e8b8cd4c04259a606.tar.zst
bun-70c3371b14293e18a5e0470e8b8cd4c04259a606.zip
Fixes #4010 (#4031)
* Fixes #4010 * Update websocket_http_client.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r--src/http/websocket_http_client.zig41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/http/websocket_http_client.zig b/src/http/websocket_http_client.zig
index ccdcda20d..333d23686 100644
--- a/src/http/websocket_http_client.zig
+++ b/src/http/websocket_http_client.zig
@@ -360,7 +360,8 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
}
}
- const wrote = socket.write(this.input_body_buf, true);
+ // Do not set MSG_MORE, see https://github.com/oven-sh/bun/issues/4010
+ const wrote = socket.write(this.input_body_buf, false);
if (wrote < 0) {
this.terminate(ErrorCode.failed_to_write);
return;
@@ -542,7 +543,8 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
if (this.to_send.len == 0)
return;
- const wrote = socket.write(this.to_send, true);
+ // Do not set MSG_MORE, see https://github.com/oven-sh/bun/issues/4010
+ const wrote = socket.write(this.to_send, false);
if (wrote < 0) {
this.terminate(ErrorCode.failed_to_write);
return;
@@ -1304,15 +1306,15 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
this.sendCloseWithBody(this.tcp, 1001, null, 0);
}
- fn enqueueEncodedBytesMaybeFinal(
+ fn enqueueEncodedBytes(
this: *WebSocket,
socket: Socket,
bytes: []const u8,
- is_closing: bool,
) bool {
// fast path: no backpressure, no queue, just send the bytes.
if (!this.hasBackpressure()) {
- const wrote = socket.write(bytes, !is_closing);
+ // Do not set MSG_MORE, see https://github.com/oven-sh/bun/issues/4010
+ const wrote = socket.write(bytes, false);
const expected = @as(c_int, @intCast(bytes.len));
if (wrote == expected) {
return true;
@@ -1323,18 +1325,18 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
return false;
}
- _ = this.copyToSendBuffer(bytes[@as(usize, @intCast(wrote))..], false, is_closing);
+ _ = this.copyToSendBuffer(bytes[@as(usize, @intCast(wrote))..], false);
return true;
}
- return this.copyToSendBuffer(bytes, true, is_closing);
+ return this.copyToSendBuffer(bytes, true);
}
- fn copyToSendBuffer(this: *WebSocket, bytes: []const u8, do_write: bool, is_closing: bool) bool {
- return this.sendData(.{ .raw = bytes }, do_write, is_closing, .Binary);
+ fn copyToSendBuffer(this: *WebSocket, bytes: []const u8, do_write: bool) bool {
+ return this.sendData(.{ .raw = bytes }, do_write, .Binary);
}
- fn sendData(this: *WebSocket, bytes: Copy, do_write: bool, is_closing: bool, opcode: Opcode) bool {
+ fn sendData(this: *WebSocket, bytes: Copy, do_write: bool, opcode: Opcode) bool {
var content_byte_len: usize = 0;
const write_len = bytes.len(&content_byte_len);
std.debug.assert(write_len > 0);
@@ -1349,7 +1351,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
std.debug.assert(!this.tcp.isClosed());
std.debug.assert(this.tcp.isEstablished());
}
- return this.sendBuffer(this.send_buffer.readableSlice(0), is_closing, !is_closing);
+ return this.sendBuffer(this.send_buffer.readableSlice(0));
}
return true;
@@ -1358,13 +1360,9 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
fn sendBuffer(
this: *WebSocket,
out_buf: []const u8,
- is_closing: bool,
- _: bool,
) bool {
std.debug.assert(out_buf.len > 0);
- _ = is_closing;
- // set msg_more to false
- // it seems to improve perf by ~20%
+ // Do not set MSG_MORE, see https://github.com/oven-sh/bun/issues/4010
const wrote = this.tcp.write(out_buf, false);
if (wrote < 0) {
this.terminate(ErrorCode.failed_to_write);
@@ -1379,10 +1377,6 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
return true;
}
- fn enqueueEncodedBytes(this: *WebSocket, socket: Socket, bytes: []const u8) bool {
- return this.enqueueEncodedBytesMaybeFinal(socket, bytes, false);
- }
-
fn sendPong(this: *WebSocket, socket: Socket) bool {
if (socket.isClosed() or socket.isShutdown()) {
this.dispatchAbruptClose();
@@ -1444,7 +1438,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
var slice = final_body_bytes[0..(8 + body_len)];
Mask.fill(this.globalThis, mask_buf, slice[6..], slice[6..]);
- if (this.enqueueEncodedBytesMaybeFinal(socket, slice, true)) {
+ if (this.enqueueEncodedBytes(socket, slice)) {
this.dispatchClose(code, &reason);
this.clearData();
}
@@ -1463,7 +1457,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
const send_buf = this.send_buffer.readableSlice(0);
if (send_buf.len == 0)
return;
- _ = this.sendBuffer(send_buf, false, true);
+ _ = this.sendBuffer(send_buf);
}
pub fn handleTimeout(
this: *WebSocket,
@@ -1502,7 +1496,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
return;
}
- _ = this.sendData(bytes, !this.hasBackpressure(), false, opcode);
+ _ = this.sendData(bytes, !this.hasBackpressure(), opcode);
}
pub fn writeString(
this: *WebSocket,
@@ -1549,7 +1543,6 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
else
Copy{ .latin1 = str.slice() },
!this.hasBackpressure(),
- false,
opcode,
);
}