Skip to content

Pyjoyment: the heartbeat of a stream of Server-Sent Events or of a WebSocket, of a helper or of a route - #614

Merged
dex4er merged 1 commit into
route-timeoutsfrom
stream-keepalive
Nov 12, 2026
Merged

dex4er merged 1 commit into
route-timeoutsfrom
stream-keepalive

Conversation

@dex4er

@dex4er dex4er commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

The third step of #266, stacked on #612: the keepalive of streams that wait, as for a model of language, so that proxies and load balancers with an idle timeout of their own, and the inactivity timeout of the server, keep them.

Changes

  • The helper heartbeat(interval=20, timeout=20):
    • for Server-Sent Events, a comment : heartbeat every interval seconds once the response is a stream of text/event-stream, which Mojolicious leaves to the application, as the documentation of write_sse says;
    • for a WebSocket, the pings of heartbeat of its transaction, which closes the connection of a peer that does not answer in timeout;
    • None stops it, and the timer goes with the end of the transaction.
  • The value heartbeat of the stash of a route, of its defaults or of a route of under before it, sets it before the first action, as the timeouts of Pyjoyment: the timeouts of a route, inactivity_timeout and request_timeout, with a 504 after its deadline #612 do: r.get('/events', {'heartbeat': 15}). It is a reserved stash value.
  • Docs: the helper, the reserved stash values of Controller.stash, the routing guide and the skill async.

Validation

  • t/Pyjoyment/heartbeat_lite_app.py with an inactivity timeout of the server of 0.3 seconds, which the bytes of a stream show, as the user agent leaves the comments out of its events: comments while it waits and the event after them, none and a closed stream without a heartbeat, the helper and its stop, a response that is not a stream, and the pings of a WebSocket that keep it open
  • On asyncio and Pyjo.Reactor.Poll, and on the reactors of Uvloop, gevent, Twisted and Trio
  • The suite on both reactors with PYTHONDEVMODE=1, without a ResourceWarning or an unhandled rejected promise
  • Sphinx with -W, trunk check

Part of #266

🤖 Generated with Claude Code

…lue heartbeat of the stash of a route

A comment of Server-Sent Events every so many seconds, once the response is a
stream of text/event-stream, or the pings of a WebSocket with heartbeat of its
transaction, so that proxies and load balancers with an idle timeout of their
own, and the inactivity timeout of the connection, keep a stream that waits,
as for a model of language. Mojolicious leaves the comments to the
application. The value heartbeat of the stash of a route, of its defaults or
of a route of under before it, sets it before the first action, and is a
reserved stash value.

Part of #266

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dex4er dex4er added this to the 0.4.0 milestone Nov 12, 2026
@dex4er
dex4er added this pull request to stack #613 November 12, 2026 15:57
@read-the-docs-community

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Docker Smoke Test

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
smoke (app) 11 11 0 0 ✅ 131305186184
smoke (fastcgi) 5 5 0 0 ✅ 131305186835
smoke (kubernetes) 8 8 0 0 ✅ 131305186692
smoke (lambda) 2 2 0 0 ✅ 131305186634
smoke (lambda-image) 5 5 0 0 ✅ 131305186759
smoke (lambda-stream) 2 2 0 0 ✅ 131305186664
smoke (lambda-zip) 9 9 0 0 ✅ 131305186729
smoke (lite) 4 4 0 0 ✅ 131305186799
smoke (lite-pep723) 4 4 0 0 ✅ 131305186623
All 50 50 0 0 ✅

The run of the workflow

@github-actions

Copy link
Copy Markdown
Contributor

Tests

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
prove (python 3.12, Asyncio) 7465 7436 29 0 ✅ 131305188104
prove (python 3.12, Poll) 7437 7406 31 0 ✅ 131305188241
prove (python 3.13, Asyncio) 7465 7436 29 0 ✅ 131305188129
prove (python 3.13, Poll) 7437 7406 31 0 ✅ 131305188207
prove (python 3.14, Asyncio) 7496 7472 24 0 ✅ 131305188220
prove (python 3.14, Poll) 7468 7442 26 0 ✅ 131305188150
prove (python 3.15, Asyncio) 7496 7472 24 0 ✅ 131305188018
prove (python 3.15, Poll) 7468 7442 26 0 ✅ 131305188146
prove (python 3.15t, Asyncio) 7496 7472 24 0 ✅ 131305188336
prove (python 3.15t, Poll) 7468 7442 26 0 ✅ 131305188229
prove (python mise, Asyncio) 7575 7540 35 0 ✅ 131305188036
prove (python mise, Asyncio, Windows) 7296 7230 66 0 ✅ 131305187912
prove (python mise, Poll) 7547 7510 37 0 ✅ 131305187972
prove (python mise, Poll, Windows) 7268 7200 68 0 ✅ 131305187510
prove (python pypy3.12, Asyncio) 7465 7436 29 0 ✅ 131305188012
prove (python pypy3.12, Poll) 7437 7406 31 0 ✅ 131305188402
pytest (python 3.12, ubuntu-26.04-arm) 442 416 26 0 ✅ 131305188026
pytest (python 3.15, ubuntu-26.04-arm) 442 421 21 0 ✅ 131305187905
pytest (python 3.15, windows-2025) 442 393 49 0 ✅ 131305188014
servers (python 3.12) 54 54 0 0 ✅ 131305188079
servers (python 3.15) 53 53 0 0 ✅ 131305188105
All 120717 120085 632 0 ✅

The run of the workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant