fix(lua.core): responses are cut off when they do not fit the socket send buffer

Đang mở Phù hợp với người mới
#243 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
lua
Lĩnh vực
networking

Hướng nghiên cứu

Lỗi nằm ở send_raw trong src/lua/core/server.lua, hàm gửi phản hồi HTTP bằng một send() không chặn duy nhất. Đọc hàm đó và áp dụng bản sửa settimeout được gợi ý hoặc xử lý các gửi một phần. Done có nghĩa là các phản hồi game-state lớn được gửi đầy đủ mà không đóng kết nối sớm.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

send_raw in src/lua/core/server.lua writes the HTTP response with a single send() on the client socket, which the server put into non-blocking mode (client:settimeout(0)), and then the connection is closed.

LuaSocket's send on a non-blocking socket writes only what fits into the kernel send buffer and returns nil, "timeout", last_byte_sent for the rest. That partial result is not handled, so a large reply (a full game state) is truncated and the client sees the connection close early.

Steps to Reproduce

  1. Run several BalatroBot instances in parallel on a loaded machine
  2. Drive normal runs that return large game states (play, gamestate in the shop).
  3. Occasionally the client gets http.client.RemoteDisconnected: Remote end closed connection without response

It seems to be load-dependent: the slower the client reads, the more likely the reply does not fit the buffer.

Expected Behavior

The whole response is delivered, however large.

Actual Behavior

The response is cut off at whatever fit into the send buffer; the rest is dropped.

Suggested Fix

Smallest change (what we run, as a patch in our container image; we have not seen a cut-off reply
in about 50 container runs since):

BB_SERVER.client_socket:settimeout(5)
local _, err = BB_SERVER.client_socket:send(response_str)

This blocks the game loop for at most 5 s if the client stops reading. If that is not acceptable, the
alternative is to keep the unsent tail (send(data, last + 1)) and finish it on the next update ticks
before closing the socket.

Environment

  • BalatroBot 1.5.2 (and dev at 2026-07-28), Balatro 1.0.1o, Steamodded 1.0.0~BETA-1814a
  • Linux container (Fedora 42, LÖVE 11.5), Python client with urllib

Files

  • src/lua/core/server.lua (send_raw)
Ngôn ngữ chính
Python
Star
79
Fork
23
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của coder/balatrobot

Tất cả issue của coder/balatrobot

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.