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

Aperta Adatta ai principianti
#243 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
lua
Ambito
networking

Direzione di ricerca

Il bug è in send_raw in src/lua/core/server.lua, che invia la risposta HTTP con un singolo send() non bloccante. Leggi quella funzione e applica la fix settimeout suggerita o gestisci invii parziali. Done significa che le grandi risposte game-state sono consegnate completamente senza chiusura anticipata della connessione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)
Lingua principale
Python
Stelle
80
Fork
23
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di coder/balatrobot

Tutte le issue di coder/balatrobot

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.