mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Fix the server on Linux, and test races it showed
Server: - Storage: #BakaShrot_Storage_SqliteLibrary, the SQLite the server loads: sqlite3.dll on Windows, the system's libsqlite3.so.0 on Linux (PB 5.73's bundled 3.33 has no JSON functions). The query error check and the writer's prepared statements use it too, so a JSON function on a row that isn't JSON is refused on Linux as well, not answered with no rows. - SendPacket: SendNetworkData() returns -1 once the send buffer is full (EAGAIN on Linux), which aborted clients reading big answers. Retried until nothing goes out for #BakaShrot_SendStallTimeout (10 s). Tests, timing they relied on: - Attachments, BigMessages: link failures before the first link are expected, Linux refuses at once where Windows retries for ~1 s. - Restart: a pusher whose server is killed between two pushes sees 100 (NotConnected), during one 104 (ConnectionLost): both accepted. - Retention: deletions counted over every retention check, a batch can be split over two. - AttachmentEdges: waits for B's corrupted attachment to be dropped, A sends it again at every check-in. All tests pass on Linux with PB 6.41 (asm and C backends). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVQCBfcPDfAPqX8z2TF
This commit is contained in:
@@ -218,6 +218,11 @@ EndProcedure
|
||||
; next packets.
|
||||
#BakaShrot_InboxKeptCapacity = 256 * 1024
|
||||
|
||||
; How long a send waits for the other end to make room, without a single
|
||||
; byte going out, before it gives up. Same as how long a client waits for
|
||||
; each packet (#BakaShrot_Outbound_Timeout).
|
||||
#BakaShrot_SendStallTimeout = 10000
|
||||
|
||||
Enumeration BakaShrot_InboxResults
|
||||
#BakaShrot_Inbox_Incomplete
|
||||
#BakaShrot_Inbox_Packet
|
||||
@@ -264,8 +269,13 @@ EndProcedure
|
||||
; *Cipher is 0: only the Hello (sealed on its own) and the ChallengeRequest.
|
||||
; Returns #False if the packet is too big, *Cipher isn't set up, or the data
|
||||
; couldn't be sent.
|
||||
; PureBasic's sockets don't block: SendNetworkData() returns -1 once the
|
||||
; system's send buffer is full (EAGAIN on Linux, a few hundred KB), so -1 is
|
||||
; retried until nothing went out for #BakaShrot_SendStallTimeout. PureBasic
|
||||
; doesn't tell that from a broken connection, which then takes that long to
|
||||
; give up on.
|
||||
Procedure.i BakaShrot_SendPacket(ConnectionId.i, *Packet, PacketSize.i, *Cipher.BakaShrot_Cipher)
|
||||
Protected *Frame, FrameSize.i, PayloadSize.i, Offset.i, Sent.i
|
||||
Protected *Frame, FrameSize.i, PayloadSize.i, Offset.i, Sent.i, LastProgress.i
|
||||
|
||||
If PacketSize < 1 Or PacketSize > #BakaShrot_MaxPacketSize
|
||||
ProcedureReturn #False
|
||||
@@ -294,13 +304,19 @@ Procedure.i BakaShrot_SendPacket(ConnectionId.i, *Packet, PacketSize.i, *Cipher.
|
||||
CopyMemory(*Packet, *Frame + #BakaShrot_FrameHeaderSize, PacketSize)
|
||||
EndIf
|
||||
|
||||
LastProgress = ElapsedMilliseconds()
|
||||
While Offset < FrameSize
|
||||
Sent = SendNetworkData(ConnectionId, *Frame + Offset, FrameSize - Offset)
|
||||
If Sent <= 0
|
||||
If Sent > 0
|
||||
Offset + Sent
|
||||
LastProgress = ElapsedMilliseconds()
|
||||
ElseIf ElapsedMilliseconds() - LastProgress > #BakaShrot_SendStallTimeout
|
||||
FreeMemory(*Frame)
|
||||
ProcedureReturn #False
|
||||
Else
|
||||
; Full, until the other end reads some of it.
|
||||
Delay(1)
|
||||
EndIf
|
||||
Offset + Sent
|
||||
Wend
|
||||
|
||||
FreeMemory(*Frame)
|
||||
|
||||
Reference in New Issue
Block a user