Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
596be9a
docs: add horse-provider-nghttp2 to providers table + README.pt-BR sync
freitasjca Aug 19, 2026
7ee7ef7
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Aug 19, 2026
6582c39
docs: merge upstream README additions; restore nghttp2 provider mention
freitasjca Aug 19, 2026
6f86751
docs: remove duplicate ICS provider row, canonicalise CrossSocket define
freitasjca Aug 20, 2026
45f8aa4
docs: remove duplicate ICS provider row, canonicalise CrossSocket define
freitasjca Aug 20, 2026
ac7467d
docs: remove duplicate ICS provider row, canonicalise CrossSocket define
freitasjca Aug 20, 2026
4d85ef5
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Aug 28, 2026
7632bbf
chore: re-apply active patches after upstream sync (FPCHttp fix + Web…
freitasjca Aug 28, 2026
e0fdc3d
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Sep 4, 2026
4e687eb
Merge upstream/master (3.3.4) into dev
freitasjca Sep 5, 2026
a574ec4
test(fpc): make the keep-alive regression test actually test keep-alive
freitasjca Sep 5, 2026
3783558
test(fpc): WebSocket EAGAIN regression test for the epoll provider
freitasjca Sep 5, 2026
bf6f236
fix(tests): restore the WebSocket epoll regression step in the Lazaru…
freitasjca Sep 5, 2026
9c3d9d5
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Sep 14, 2026
3ab2b4e
Merge branch 'fix/decode-once' into dev
freitasjca Sep 14, 2026
0992208
Merge branch 'fix/decode-once' into dev
freitasjca Sep 14, 2026
a5f4189
Merge branch 'fix/decode-once' into dev
freitasjca Sep 14, 2026
a87a0ea
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Sep 18, 2026
b5695f2
Merge branch 'fix/graceful-instance-shutdown' into dev
freitasjca Sep 27, 2026
c94de6c
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Sep 27, 2026
7ec06ee
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Sep 30, 2026
9e2849e
docs(readme): drop the duplicate horse-prometheus-metrics row left by…
freitasjca Oct 3, 2026
ff29cbc
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Oct 5, 2026
38bb223
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Oct 7, 2026
e63fe02
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Oct 12, 2026
7d45ef0
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Oct 23, 2026
4bedcfe
Merge remote-tracking branch 'upstream/master' into dev
freitasjca Nov 1, 2026
b67a9ea
fix: guard HttpSys SendResponse against a nil custom-header dict
freitasjca Nov 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ benchmarks/results/

# FPC test binaries (Linux builds have no extension, so *.exe misses them)
tests/src/FPCHttpKeepAliveServer
tests/src/FPCHttpKeepaliveTest
26 changes: 26 additions & 0 deletions samples/tests/Horse.Indy.TestRoutes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,32 @@ procedure RegisterTestRoutes;
end
);

// ── FIX-HTTPSYS-CORS-NIL regression: header set ONLY via RawWebResponse ───
// Reproduces the http.sys AV: when a response header arrives only through
// Res.RawWebResponse.SetCustomHeader and AddHeader is NEVER called (exactly
// what Horse.CORS does), the shadow CustomHeaders dict stays nil while the
// raw header count is > 0 — so THttpSysRawResponse.SendResponse's for..in
// enumerated a nil dict and AV'd. Provider-agnostic: Indy/Epoll/IOCP always
// passed; this route is the guard for HttpSys.
THorse.Get('/raw/setheader-only',
procedure(Req: THorseRequest; Res: THorseResponse)
var
LRaw: TRawWebRes;
begin
LRaw := Res.RawWebResponse;
if not Assigned(LRaw) then
begin
Res.ContentType('application/json; charset=utf-8').Status(500)
.Send('{"error":"RawWebResponse is nil"}');
Exit;
end;
// Deliberately NO Res.AddHeader anywhere — the shadow header dict must
// remain nil so the HttpSys nil-enumeration path is exercised.
LRaw.SetCustomHeader('X-Raw-Only', 'raw-only-ok');
Res.Send('raw-only-ok');
end
);

// ── PATCH-REQ-9: double-read idempotency ─────────────────────────────────
THorse.Post('/echo/body-twice',
procedure(Req: THorseRequest; Res: THorseResponse)
Expand Down
14 changes: 14 additions & 0 deletions samples/tests/HorseNetHttpTestClient.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,20 @@ begin
(R.StatusCode = 200) and (R.Body = 'pong'),
Format('%d / %s', [R.StatusCode, R.Body]));

// ── 37 ─────────────────────────────────────────────────────────────────────
// FIX-HTTPSYS-CORS-NIL: a header set ONLY via RawWebResponse.SetCustomHeader
// (no AddHeader) must not AV the HttpSys provider. Pre-fix: http.sys
// SendResponse enumerated a nil shadow dict -> AV / dropped connection.
// Post-fix: 200 + header. Passes on every other provider too.
Section('37 GET /raw/setheader-only (FIX-HTTPSYS-CORS-NIL - SetCustomHeader, no AddHeader)');
DoReq(LClient, 'GET', BASE_URL + '/raw/setheader-only', nil, nil, R);
Check('status 200', R.StatusCode = 200, IntToStr(R.StatusCode));
Check('body = "raw-only-ok"', R.Body = 'raw-only-ok', R.Body);
if Assigned(R.Response) then
Check('X-Raw-Only: raw-only-ok',
R.Response.HeaderValue['X-Raw-Only'] = 'raw-only-ok',
R.Response.HeaderValue['X-Raw-Only']);

finally
LClient.Free;
end;
Expand Down
5 changes: 5 additions & 0 deletions src/Horse.Provider.HttpSys.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,11 @@ procedure THttpSysRawResponse.SendResponse(const ARes: THorseResponse);
Inc(LHdrIdx);
end;
{$ELSE}
// FIX-HTTPSYS-CORS-NIL: the shadow CustomHeaders dict is nil when headers arrived only via
// RawWebResponse (e.g. Horse.CORS calls Res.RawWebResponse.SetCustomHeader, never AddHeader),
// yet the block is entered because LRawHeaderCount/LRepeatCount > 0 — so guard the for..in.
// (The FPC branch above is already guarded by LHeaderCount, which is 0 when the dict is nil.)
if LHeadersList <> nil then
for LPair in LHeadersList do
if not SameText(LPair.Key, 'Set-Cookie') then
begin
Expand Down
199 changes: 199 additions & 0 deletions tests/src/FPCHttpKeepaliveTest.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
program FPCHttpKeepaliveTest;

{ Regression test for the FPC keep-alive latency stall (HashLoad/horse#562,
fixed upstream in 3.3.4 by PR #563).

ROOT CAUSE — Nagle interacting with the peer's delayed ACK, NOT a poll
interval. fphttpserver writes each response as two send() calls: the header
block, then the body. TCP_NODELAY was never set on the accepted socket, so
Nagle held the small second write until the peer ACKed the first, and the
peer — having nothing to send — waited out its ~40 ms delayed-ACK timer.

Established by wire capture: the body segment leaves 11-14 us after the ACK
arrives, three times, while the ACK delay itself varies 42.5-43.9 ms. The
body tracks the ACK to microseconds across a varying delay, which only Nagle
produces. An earlier reading of this file blamed "a fixed ~40 ms select()
poll interval"; that was wrong, and this header used to state it as fact.
The server IS idle in select() for ~43 ms, but waiting for the next request,
which the client cannot send because it is still waiting for a body Nagle is
holding. Cause and effect inverted.

THE FIX THIS GUARDS — Horse.Provider.FPC.HTTPApplication sets TCP_NODELAY on
each accepted socket via THorseNoDelaySocketHandler.Accept, wired through
OnGetSocketHandler, and enables KeepConnections together with a positive
KeepConnectionTimeout. Both halves are required: KeepConnections alone
leaves WaitUntil at 0, so the connection thread serves exactly one request
and exits.

WHY KeepConnection := True BELOW IS LOAD-BEARING — the stall only appears on
a REUSED connection. TFPHTTPClient.KeepConnection defaults to False, so
without setting it every request gets a fresh socket, and Linux starts every
socket in quickack mode: the first ACK is immediate, Nagle never engages, and
this test passes whether or not the fix is present. That is precisely how it
was written before, and it made the test decorative.

WHAT THIS CHECKS
1. REQUEST_COUNT sequential GETs, all on ONE connection, each completing
within STALL_THRESHOLD_MS. The stall is ~44 ms when present and well
under 1 ms when fixed, so 35 ms separates the two cleanly while leaving
headroom over scheduling jitter.
2. Every response is HTTP 200 with the body 'pong'.
3. No hang — the process exits rather than blocking.

Complements tests/fpc_keepalive_regression.py, which upstream added with the
fix. That one drives FPCHttpKeepAliveServer.dpr from Python; this one is
self-contained Pascal and runs where grpc_tools/Python are not installed.

Build (from horse/tests/src/) — TRUNK, not the distro compiler. A bare `fpc`
finds 3.2.2 on Ubuntu and the version guard below rejects it:

U=/usr/local/fpc-trunk/lib/fpc/3.3.1/units/x86_64-linux
mkdir -p /tmp/ka-test
/usr/local/fpc-trunk/bin/fpc -MDelphi -Sh -B -n \
-Fu"$U/*" -Fu"$U" -Fu../../src \
-FU/tmp/ka-test -FE/tmp/ka-test FPCHttpKeepaliveTest.dpr
/tmp/ka-test/FPCHttpKeepaliveTest

The -n and explicit -Fu are not optional: without them trunk reads
/etc/fpc.cfg, finds the distro's 3.2.2 units and dies with
"PPU Invalid Version 207 expecting 208" — which reads as a missing unit but
is really a wrong-compiler unit.

No HORSE_* define is needed: on FPC with no provider define, Horse.pas
selects Horse.Provider.FPC.HTTPApplication automatically. Indy never enters
the picture on FPC. Requires FPC >= 3.3.1 — the provider's keep-alive and
TCP_NODELAY code sits behind an $IF FPC_FULLVERSION >= 30301 guard, so on
3.2.2 it is not merely untested, it is not compiled.

(That guard is written without its braces on purpose: a directive's closing
brace would end this comment early and the prose after it would be compiled.)
}

{$MODE DELPHI}{$H+}

// Refuse to build on a compiler where the code under test does not exist.
// The provider's keep-alive and TCP_NODELAY handling sit behind a
// FPC_FULLVERSION >= 30301 guard, so on 3.2.2 the server never keeps a
// connection open. This test sets KeepConnection := True on the client, so
// the run then dies with "Error reading data from socket" on the third
// request - a socket error that says nothing about the real cause. Failing
// at compile time names it instead.
{$IF FPC_FULLVERSION < 30301}
{$FATAL This test requires FPC 3.3.1+. On 3.2.2 the provider's keep-alive and TCP_NODELAY code is not compiled at all, so there is nothing here to test.}
{$ENDIF}

uses
{$IFDEF UNIX}cthreads,{$ENDIF}
SysUtils, Classes, fphttpclient,
Horse, Horse.Commons;

const
TEST_PORT = 9901;
REQUEST_COUNT = 30;
STALL_THRESHOLD_MS = 35; { any single request above this = stall detected }
SERVER_STARTUP_MS = 1500; { allow fphttpserver to finish binding }

procedure PingHandler(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
begin
Res.Send('pong');
end;

type
TServerThread = class(TThread)
protected
procedure Execute; override;
end;

procedure TServerThread.Execute;
begin
FreeOnTerminate := True;
try
THorse.Listen(TEST_PORT, '127.0.0.1');
except
on E: Exception do
Writeln('Server: ', E.Message);
end;
end;

var
LClient: TFPHTTPClient;
LStart: QWord;
LElapsed, LMax, LTotal: QWord;
LBody: string;
LStatusCode: Integer;
LFailed: Boolean;
I: Integer;
begin
Writeln('FPC keep-alive latency regression test (horse#562)');
Writeln(' requests : ', REQUEST_COUNT, ' (one reused connection)');
Writeln(' stall threshold: ', STALL_THRESHOLD_MS, ' ms');

THorse.Get('/ping', PingHandler);

TServerThread.Create(False);
Sleep(SERVER_STARTUP_MS);

LClient := TFPHTTPClient.Create(nil);
{ Load-bearing, not a tuning knob. Defaults to False, and with a fresh
connection per request Linux quickack keeps every first ACK immediate, so
Nagle never engages and this test passes with or without the fix. }
LClient.KeepConnection := True;
LFailed := False;
LMax := 0;
LTotal := 0;
try
for I := 1 to REQUEST_COUNT do
begin
LStart := GetTickCount64;
try
LBody := LClient.Get(Format('http://127.0.0.1:%d/ping', [TEST_PORT]));
LStatusCode := LClient.ResponseStatusCode;
except
on E: Exception do
begin
Writeln('FAIL: request ', I, ' raised ', E.ClassName, ': ', E.Message);
LFailed := True;
Continue;
end;
end;

LElapsed := GetTickCount64 - LStart;
LTotal := LTotal + LElapsed;
if LElapsed > LMax then
LMax := LElapsed;

if LStatusCode <> 200 then
begin
Writeln(Format('FAIL: request %2d status=%d body="%s"', [I, LStatusCode, LBody]));
LFailed := True;
end
else if LBody <> 'pong' then
begin
Writeln(Format('FAIL: request %2d body="%s" (expected "pong")', [I, LBody]));
LFailed := True;
end
else if LElapsed > STALL_THRESHOLD_MS then
begin
Writeln(Format('FAIL: request %2d %3d ms > %d ms -- Nagle/delayed-ACK stall detected',
[I, LElapsed, STALL_THRESHOLD_MS]));
LFailed := True;
end;
end;
finally
LClient.Free;
end;

Writeln(Format(' max latency : %d ms', [LMax]));
Writeln(Format(' avg latency : %d ms', [LTotal div REQUEST_COUNT]));

if LFailed then
begin
Writeln('RESULT: FAIL');
ExitCode := 1;
end
else
begin
Writeln(Format('RESULT: OK (all %d requests <= %d ms)', [REQUEST_COUNT, LMax]));
ExitCode := 0;
end;
end.
Loading