Repository navigation
5.5.0
Fixed
-
An HTTP/2 exchange whose response was cut off by the client is returned
to the pool again. Two cases skipped it: a handler answering a stream the
client had already reset (the 500 for aClientDisconnectedraised from
a body read, or a handler catching its cancel and still responding), and
any response in flight when the connection was lost, which is every SSE
stream whose browser tab closes on HTTP/2. The exchange was still freed by
the cyclic garbage collector, but held its buffers until then and cost a
fresh allocation on the next request. Writes for a stream that no longer
exists are now dropped. -
A lingering close (the FIN after a 413 while the client is still
uploading) no longer waits forever on a peer that stops reading: the
socket is closed after the linger window, and aborted one window later
ifclose()is still waiting for the peer to take the buffered response. -
One connection raising inside the timeout sweep no longer leaves the
other connections unchecked or stops the sweep until the next connection
opens. -
stario_cython.xxh64.updaterefuses a non-contiguous memoryview instead
of hashing the underlying buffer as if it were contiguous. -
A plain tuple in child position is no longer rendered as markup. Elements
built byh.*are now anElement(atuplesubclass) and the renderer
and@bakeddispatch on that type, so a four-column database row passed
as one child raisesStarioErrorinstead of writing its text to the
page unescaped.h.Li(*row)keeps escaping each cell. -
h.Scriptandh.Styleare raw-text elements:strchildren are sent
as they are, because the browser never decodes entities inside them, so
h.Script("if (a < b) go()")now works. Text that would end the element
early (</script,<!--in a script,</style) raisesStarioError;
the check runs once over the joined children, soh.Script("</scr", "ipt>")fails likeh.Script("</script>")does. A@bakedparameter
insideh.Scriptorh.Styleis spliced verbatim too, with the same
joined check on every call.Tag(name, raw_text=True)marks a custom
raw-text tag. -
The compiled attribute-name cache and the
classes()fragment cache
stop filling at their cap instead of being cleared in place, and the
name cache reads with a strong reference, so a build on one thread can
no longer free an entry another thread is reading under free threading. -
data.on("myEvent", …)emitsdata-on:my-event__case.camel, and
data.class_("myClass", …)emitsdata-class:my-class__case.camel
(__case.pascalfor PascalCase), so the browser's lowercasing of the
attribute name no longer changes the event or class name.data.attr
anddata.styleraise for a key with uppercase letters (HTML lowercases
it; usedata.attrs/data.styles), as dodata.bind(prop=…)and
data.bind(event=…)for modifier values with uppercase letters. -
An HTTP/2 request body that grows past the read limit while the handler
is reading it is answered once, by the handler'sRequestBodyErrorpath
(413 with a text body, as on HTTP/1). The protocol no longer sends its
own empty 413 first, which left the request span marked as a failure. -
HTTP/2 writes queued behind a slow reader are compacted only once half
of the buffer has been sent. Before, every DATA frame sent moved the
whole unsent backlog, so a handler that did notdrain()paid for the
backlog size on each frame. -
A span that fails with an exception whose message is empty (
KeyError(),
asyncio.CancelledError()) is exported with statuserror, and the
error text is the exception type name. Before, the JSON, SQLite, and
test tracers exported it asokwith no error. -
JsonTracerandSqliteTracerkeep spans that end while the tracer
exits: the writer thread drains them before it stops. Before, a span that
ended between the stop request and the join was dropped and logged as
ended "while stopped". -
TTYTracerexit no longer waits forever on a terminal write that is
stuck. The final render and the stdout/stderr drain give up after one
second, like the render thread join. -
set_cookie(expires="Wed, 21 Oct 2015 07:28:00 GMT")works. Thestr
form rejected a comma, which every HTTP-date contains.;is still
rejected. -
A
Rangeheader with several ranges (bytes=0-1,3-4) is answered 200
with the full body, as RFC 9110 14.2 allows. Before it was 416. -
Filesno longer raisesKeyErrorwhen two event-loop threads
(STARIO_THREADSabove 1) evict the same changed file from the cache.
Changed
-
HTTP/2 writes one buffer per send pass: every HEADERS and DATA frame
nghttp2 produced for all streams, in order, goes to the transport in one
writelines. Before, each DATA frame was its own transport call behind a
flush of the frames before it, so a response with a body cost two writes
(two TLS records) and a 64 KiB body cost five. Nothing is written from
inside an nghttp2 callback any more.benchmarks/server/inproc.pygained
h2_*cases that also print writes per request. -
Text and attribute escaping for strings with characters above U+00FF
(CJK, emoji) runs in one C pass like Latin-1 text: a 60-character CJK
string with&,<,>escapes in 0.14 µs instead of 0.42 µs; clean
strings still return the same object. -
STARIO_MALLOC_TUNE=0leaves glibc's malloc thresholds alone. The
64 MiB mmap and trim thresholds Stario sets on first use are now
documented inCYTHON.md, including that the trim threshold applies per
malloc arena (per allocating thread). -
One clock per event loop.
Connections(one per loop) now owns the
timeout tick: a singleloop.call_laterhandle, scheduled only while a
connection with timeouts exists, readsloop.time()once and walks the
live connections in C. TheServerno longer runs aDatecoroutine per
loop, and an idle loop makes no timer wakeups. TheDateheader comes
from a per-second cache on the same object: one coarse wall-clock read
per response, reformatted in C only when the second changed, so a busy
loop can no longer serve a staleDate. The lingering-close wait and
the HTTP/2 GOAWAY grace are deadlines on that tick instead of timers,
so the protocol holds noTimerHandle. With timeouts off
(timeout_cleanup="off", the test client) a lingering close closes
at once. -
HttpProtocol(loop, app, tracer, compression, connections, ...)no
longer takes adate_boxlist;Connections(date=...)or
Connections.pin_date()fixes theDateline for tests, and
Connections.date_linereads it.Connections(server_driven=...)is
gone: a registry always ticks itself. -
SSE.patch_elementsdocuments thatbytesandstrare trusted HTML
sent as they are (likew.html); build user text withh.*. -
at.get/post/put/patch/delete/queryshare one
FetchOptionstyped dictionary (**options: Unpack[FetchOptions])
instead of six copies of the option list. Calls are unchanged. -
Building an element is cheaper:
Tag.__call__tests child types before
theMappingcheck, inlines thestrattribute path, and builds its
repronly for errors;classes()checksstrtokens first and caches
the fragment for repeated all-strargument tuples;styles()scans
names and values with one regex each.escape_attribute_valueis no
longer cached. Output is byte-identical. The 50-row page in
benchmarks/server/inproc.pygoes from 219 µs to 173 µs per request. -
An SSE payload with no line breaks (rendered markup, compact JSON) is
written without being copied through the line splitter, and signal
patches with no dotted key skip the path check. -
A full span queue in
JsonTracer/SqliteTracerwrites at most one
message per second to stderr. The message carries the number of spans
dropped since the previous one;stats().dropped_spansstill counts
every drop. -
A span keeps at most 1000 events. Later events are dropped and counted,
and the span ends with the attributespan.dropped_eventswhen the
count is above zero. -
A recorded span costs less: on the in-process benchmark a traced
plaintext request went from about 27 µs to about 9 µs on one machine.
Span ids come from a per-thread uuid7 state with pooledos.urandom
bytes instead of a process-wide lock and one syscall per id, so ids are
monotonic within one thread only. The span lock is taken directly
instead of through a generator, and the JSON serializer formats ids
withoutstr(). -
Internal:
RecordingSpan.mutexis always a context manager (a no-op one
by default) instead ofNone.RecordingSpan.duration_nsand the
unusedstario._terminal.style_text/styledare removed. -
Assets.load()reads each file once. It holds the bytes while they fit
max_bytesand only fingerprints the files after that. Before, every
file undermax_file_sizewas read into memory before the budget
applied, and every file was hashed from disk a second time. A file
pinned byhref()beforeload()is still verified against the disk. -
read_formopens a file spool only when a file part has a filename or
carries bytes. A file input left empty (filename="") counts toward
max_fieldslike an empty field, not towardmax_files, so a form with
many optional file inputs still posts. Before, each empty part allocated
and closed a spool and never counted, so an unlimited number of them was
accepted. -
Building and rendering markup runs in C.
Tag.__call__, the render
walk,escape_text, andescape_attribute_valuelive in
stario_cython.markup;stario.markup.tag,.render, and.escape
re-export them. Elements, the@bakedplan,SafeString,Attrs, and
every error message are unchanged, and the output is byte-identical.
On the in-process benchmark the 50-row page goes from 219 µs to 57 µs
per request; oneh.Div("text")goes from 0.45 µs to 0.09 µs, and the
naive tree-per-call page now renders in the same time as a compiled
Jinja2 template (benchmarks/html/compare.py: 127 µs against 121 µs).
Tag.empty_modeis the name of theempty=setting on a tag. -
Files.href()builds the URL without reading the disk. Before, it
resolved the path and checked for a regular file: about ten syscalls on
the event loop for each call, so a page that listed 200 uploads blocked
the loop for 2000 of them. A missing file, a directory, or an uncontained
symlink is a 404 on GET, as before. A hidden segment still raises unless
include_hidden=True. -
FilesandAssetsresolve the real path of the directory once, on the
first request, not on every request. It is resolved again only when a
served file no longer lies under it, as after a re-pointed directory
symlink. -
Relaykeeps the subscribers of a pattern in an insertion-ordered dict,
so leaving is O(1) instead of a rebuild of the bucket under the registry
lock. 2000 subscribers of one pattern leaving at shutdown no longer costs
O(N²). Delivery order is unchanged. -
read_formgathers the chunks of an upload that moved to disk and writes
them in one thread hop per 1 MiB, or at the end of the part, not one hop
per body chunk. A 1 GB upload is about a thousand executor jobs instead
of thousands. Themax_file_sizecheck runs per chunk, and a cancelled
request still waits for the thread, as before. -
Internal:
FilesandAssetsanswer a request through one_Mount._serve
pipeline (validators,Range, content-coding, then 304 / 416 / 206 / 200)
instead of three copies of it. The response bytes are unchanged.
Added
stario.testing.VirtualTimeLoop: an asyncio loop whose clock advances
only when the loop would otherwise block on a timer.asyncio.sleep,
loop.call_later,loop.time()deadlines and the connection timeout
tick all run in virtual time, with real sockets and the real protocol,
so a 30 s timeout costs milliseconds of wall time.tests/cythonruns on
it through apytest_asyncio_loop_factorieshook.
Removed
stario.http.wire.parse_accept_encodinglives in
stario.http.compression.decode_pathwas
stario_cython.exchange.decode_request_path;decode_methodhad no
caller.- From
stario.http.compression:Compressor,
CompressionConfig.make_compressor(),select(),may_compress(),
merge_vary,brotli_decompress, andzstd_decompress. The Cython
writer encodes responses itself.compress_bytes(config, encoding, data)
encodes one body for precompressed files,Headers.unsafe_merge_vary(token)
replacesmerge_vary, and the decoders are instario_cython.codecs. stario.datastar.format.case_modifier, which had no caller.