• Web server: HTTPS connections are closed right after a reply despite C

    From Rob Swindell@1:103/705 to GitLab issue in main/sbbs on Thursday, November 19, 2026 18:19:47
    open https://gitlab.synchro.net/main/sbbs/-/work_items/1370

    Over HTTPS the web server answers with `Connection: Keep-Alive` and then
    closes the connection a fraction of a second later. A client that reuses
    the connection loses its next request.

    **Measured** (v3.22, Linux, master as of 2026-11-19) with two requests
    sent on ONE connection, pausing between them:

    | pause | HTTPS (443) | HTTP (80) |
    |---|---|---|
    | none | 2nd answered | 2nd answered |
    | 0.3 s | end of file | 2nd answered |
    | 2 s | end of file | 2nd answered |

    Same result for a static file (.css) and for an .ssjs request. The log
    shows `Session thread terminated after 1 requests` about a second after
    each reply, with MaxInactivity = 1m.

    **Effect:** browsers pool connections on the strength of the Keep-Alive
    header. Chrome re-sends a request that dies on a reused connection;
    Safari does not re-send a POST, so the request fails outright ("Load
    failed"). Seen from Safari on iOS: the POST that follows another by
    under a second failed nearly every time. Every HTTPS client also pays a
    new TLS handshake per request.

    **Likely cause** (from reading websrvr.cpp; being confirmed with a
    scratch server): in `sockreadline()` the wait for the socket to become
    readable is skipped when `session->is_tls && session->tls_pending`. `tls_pending` is still true after the previous request was read, so the
    next read goes straight to `sess_recv()` -> `cryptPopData()`, which
    returns 0 bytes when nothing has arrived yet; `sess_recv()` clears `tls_pending` and returns -1, and `sockreadline()`'s `case -1:` closes
    the session for any TLS connection
    (`if (session->is_tls || SOCKET_ERRNO != EAGAIN)`). A plain connection
    takes the other branch and waits up to max_inactivity. Expected: on "no
    data yet", go back to waiting on the socket.

    **Note for whoever deploys a fix:** HTTPS connections will then really
    stay open for up to MaxInactivity, so more idle session threads are
    held at a time than today.

    -- *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell@1:103/705 to GitLab note in main/sbbs on Thursday, November 19, 2026 18:51:52
    https://gitlab.synchro.net/main/sbbs/-/work_items/1370#note_11075

    Cause confirmed on a scratch HTTPS server (loopback, MaxInactivity 60),
    with two corrections to the description above:

    - There is no tolerance window. The TLS session's read timeout is 0, so
    whenever nothing has arrived at the moment the server gets back to
    reading, `cryptPopData()` returns CRYPT_OK with 0 bytes (or
    CRYPT_ERROR_TIMEOUT for a partial record), `sess_recv()` returns -1,
    and both `sockreadline()` and `recvbufsocket()` close the session on
    -1. The ~0.3 s measured is only how long the server takes to get back
    to reading.
    - A second path has the same flaw: `session_check()`, used while
    waiting for more of a POST body, treats CRYPT_OK with 0 bytes (a
    partial TLS record) as a disconnect. A request line or a POST body
    that arrives in two pieces with a pause, or split inside a TLS record,
    is dropped.

    History: TLS reads have skipped the wait on the socket since TLS support
    was added (2015-08); the session's read timeout went to 1 s in 2018-02
    and to 0 in 2018-03. So HTTPS keep-alive across any pause has not
    worked since 2018-03. Nothing in the history says it was intended.

    Before the fix, 2 or 5 requests on one TLS connection with gaps of
    0.3 / 2 / 10 s: only the first answered. After: all answered; an idle connection and a stalled half request line close at MaxInactivity with
    the usual log line; a client close still ends the thread within about a
    second; no CPU use while waiting. Built and tested with GCC on Linux
    only. A fix is committed locally (not pushed yet).

    Deployment note, measured against typical settings: with MaxInactivity
    1m, MaxClients 200 and 10 connections per address, about 33 browsers
    holding 6 connections each could occupy every client slot for a minute.
    Plain HTTP has always behaved this way; HTTPS now matches it.

    -- *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell@1:103/705 to GitLab note in main/sbbs on Thursday, November 19, 2026 18:51:58
    https://gitlab.synchro.net/main/sbbs/-/work_items/1370#note_11075

    Cause confirmed on a scratch HTTPS server (loopback, MaxInactivity 60),
    with two corrections to the description above:

    - There is no tolerance window. The TLS session's read timeout is 0, so
    whenever nothing has arrived at the moment the server gets back to
    reading, `cryptPopData()` returns CRYPT_OK with 0 bytes (or
    CRYPT_ERROR_TIMEOUT for a partial record), `sess_recv()` returns -1,
    and both `sockreadline()` and `recvbufsocket()` close the session on
    -1. The 0.3 s or so measured is only how long the server takes to get back
    to reading.
    - A second path has the same flaw: `session_check()`, used while
    waiting for more of a POST body, treats CRYPT_OK with 0 bytes (a
    partial TLS record) as a disconnect. A request line or a POST body
    that arrives in two pieces with a pause, or split inside a TLS record,
    is dropped.

    History: TLS reads have skipped the wait on the socket since TLS support
    was added (2015-08); the session's read timeout went to 1 s in 2018-02
    and to 0 in 2018-03. So HTTPS keep-alive across any pause has not
    worked since 2018-03. Nothing in the history says it was intended.

    Before the fix, 2 or 5 requests on one TLS connection with gaps of
    0.3 / 2 / 10 s: only the first answered. After: all answered; an idle connection and a stalled half request line close at MaxInactivity with
    the usual log line; a client close still ends the thread within about a
    second; no CPU use while waiting. Built and tested with GCC on Linux
    only. A fix is committed locally (not pushed yet).

    Deployment note, measured against typical settings: with MaxInactivity
    1m, MaxClients 200 and 10 connections per address, about 33 browsers
    holding 6 connections each could occupy every client slot for a minute.
    Plain HTTP has always behaved this way; HTTPS now matches it.

    -- *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell@1:103/705 to GitLab issue in main/sbbs on Thursday, November 19, 2026 19:19:25
    close https://gitlab.synchro.net/main/sbbs/-/work_items/1370
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)