https://gitlab.synchro.net/main/sbbs/-/commit/d7ce390ffa7c29afeeea9014
Modified Files:
src/sbbs3/websrvr.cpp
Log Message:
websrvr: keep an idle kept-alive HTTPS connection open
Over HTTPS the server answered with "Connection: Keep-Alive" and then
closed the connection as soon as it went back to read the next request
and found it had not arrived yet. A browser that reused the connection
after any pause lost the request (Safari does not resend a POST). Plain
HTTP was not affected.
sockreadline() and recvbufsocket() skip the wait for a readable socket
while session->tls_pending is set, and tls_pending stays set after a
request has been read. The next read went straight to cryptPopData(),
which is non-blocking (CRYPT_OPTION_NET_READTIMEOUT is 0): with nothing received it returns CRYPT_OK with 0 bytes, or CRYPT_ERROR_TIMEOUT for a
partial record. sess_recv() returned -1 for both, and the callers treat
-1 on a TLS session as an error and close it. So a TLS session got no
idle time at all: the next request, or the rest of a request line or
POST body, had to be in hand already. The same "no data yet" case also
hit session_check() (used to wait for more of a POST body), which took
CRYPT_OK with 0 bytes from a partial record for a closed connection.
Reading without a select() first goes back to the TLS support of
dbbfabf1b1 (funky-27-foam, 2015-08-20); then cryptlib's default read
timeout bounded the idle time. 98b9d23ddd (tight-73-wife, 2018-02-15)
lowered it to 1 second "since we select() first anyway", and
3be7d67b5f (flour-3-formed, 2018-03-13) to 0, which left no idle time.
The session_check() case came with 50258e70bf (notion-31-talks,
2026-06-04).
Now sess_recv() clears tls_pending when cryptPopData() delivers nothing (CRYPT_OK with 0 bytes, or CRYPT_ERROR_TIMEOUT), and sockreadline() and recvbufsocket() then go back to waiting on the socket, up to
MaxInactivity, as for a plain connection. A peer close or a TLS error (CRYPT_ERROR_COMPLETE, CRYPT_ERROR_READ) leaves tls_pending set and
still ends the session at once. session_check() treats CRYPT_OK with 0
bytes like CRYPT_ERROR_TIMEOUT: connected, no data yet.
Reproduced and verified on a scratch web server on loopback with TLS
(Python client, certificate checks off). Before: a second request on
one TLS connection after a 0.3, 2 or 10 second pause got EOF, as did a
request line or POST body sent in two parts with a pause (also when cut
in the middle of a TLS record). After: two and five requests per
connection with pauses of 0, 0.3, 2 and 10 seconds all answered,
static and .ssjs, GET and POST; the split request line and POST bodies
are read; an idle connection is closed after MaxInactivity with the
"Session timeout due to inactivity" log line, as is half a request
line; a client close (FIN alone or close_notify) ends the session
thread as before; no CPU used while a connection waits; plain HTTP
unchanged. As a plain one already did, an idle kept-alive HTTPS
connection now holds its session thread, and delays a server shutdown,
for up to MaxInactivity. Built with GCC only.
Fixes #1370
Co-Authored-By: Claude Opus 5.5 <
noreply@anthropic.com>