Repository navigation
Amber 2.0.0-beta.18
Pre-releaseAmber 2.0.0-beta.18
Amber 2.0.0-beta.18 lets one server process stay up on the smallest droplet
(1 vCPU, 512 MB) with TLS on. A connection limit keeps memory bounded, and
four wall-clock deadlines stop slow or idle clients from holding the
connections.
The release also brings:
- HTTP/2 next to HTTP/1.1, on by default, and an HTTP/2 client,
Amber::HTTP2::Client. - Typed CBOR (
Amber::Schema::CBOR::Serializable), a COSE object API, and
COSE sealing in data-independent timing. - Mica and Beryl as shard dependencies.
- A route audit and a glob-routing fix.
- Leaner request handling: JSON bodies are read without a 64 KiB buffer, and
a JSON request allocates 527 bytes less than in Round 27.
This release ships with Beryl 0.2.6 and Mica 0.4.0, which Amber pins in
shard.lock. The current Amber CLI is 2.0.21, which still generates apps
pinned to 2.0.0-beta.17. The CLI release that pins this beta follows, with
crystal-mysql 0.20.0 for MySQL apps. Once it ships, generated apps will
write the tuned connection settings below. Until then, move an app to this
beta by hand (see Upgrading).
Connection limits and deadlines
Each key in this table defaults to 0, so an app that sets none of them keeps
its connection handling. Each key has an AMBER_SERVER_* variable and is
checked again at start.
| Key | What it bounds | amber new will write |
|---|---|---|
server.max_connections |
Connections one process holds open. At the limit the server stops accepting, and clients wait in the listen backlog. | 3000 |
server.request_head_timeout_seconds |
Each whole request head: from accept for the first request (TLS handshake included), from the first byte of a later one | 10 |
server.request_body_timeout_seconds |
Each whole request body, from the end of its head | 30 |
server.write_timeout_seconds |
Response progress: extended each time the client accepts another 64 KiB, so downloads and streams that keep moving continue | 30 |
server.keep_alive_timeout_seconds |
The wait for the next request's first byte | 60 |
How the limit and deadlines are enforced:
- One reaper fiber per server runs about every 250 ms. It shuts down each
connection past its deadline with shutdown(2), without flushing, in a
fiber of its own, and logs it once at debug. - The deadlines hold over HTTP and HTTPS alike, however the IO underneath
reads. - The app's own work on a request has no deadline. A WebSocket or HTTP/2
connection has none from these settings either. - With a limit set, the server raises its soft open-file limit to fit, or
lowers the limit to fit with one warning. - At start, the server logs its limit, backlog and deadlines.
Behavior to know:
- A body read that the body deadline ends raises
HTTP::Server::ClientErrorin the app. This holds over plain HTTP and
TLS, so an action never takes a truncated body for the whole one.
Amber::Pipe::Errorand the schema body parsers (JSON, forms, CBOR, COSE,
registered parsers) let that error through, and the server ends the
connection quietly, with no 400 or 500 logged. - Start reading the body within the body deadline. A body first read
after the deadline is refused, and the request is dropped with no
response, even when every byte has arrived. Abefore_actionthat waits
longer thanrequest_body_timeout_secondsbefore the action reads
paramshas that effect. - A WebSocket upgrade request that has a body is answered 400 and
closed, whenever any deadline is set. That covers chunked bodies and a
Content-Lengthabove 0, sent once or repeated. RFC 6455's handshake is
a GET without a body.
Related settings, each new in this release, with its default:
server.listen_backlog: 4,096 (Crystal's own is 128). Every listener
uses it: TCP, TLS and UNIX socket.server.ssl.cipher_suites:TLS_AES_128_GCM_SHA256,
TLS_CHACHA20_POLY1305_SHA256,TLS_AES_256_GCM_SHA384, in that order.server.ssl.key_exchange_groups:x25519,secp256r1, in that order.server.ssl.session_ticket_count: 1.server.gc_free_space_divisor: 0, which keeps the collector's own value.server.http2.enabledandserver.http2.h2c: both true (see HTTP/2).
The values the next amber new will write come from Round 28 AC1:
- an idle TLS connection on Beryl costs about 61 KiB;
- a 512 MB droplet held about 3,900 to 4,300 of them;
- a server holding 4,500 was killed for running out of memory.
HTTP/2
The server speaks HTTP/2 (RFC 9113) next to HTTP/1.1 on the same listeners,
and it is on by default:
- Over TLS, the listener offers
h2andhttp/1.1in ALPN. - A plaintext or UNIX-socket connection that opens with the HTTP/2 preface is
served as prior-knowledge h2c.
Amber::Server starts an Amber::HTTP2::DualProtocolServer, and every
HTTP/2 request reaches the pipeline as an ordinary HTTP::Server::Context.
Settings live in server.http2, with AMBER_SERVER_HTTP2_* overrides.
HTTP/2 connections run under that section's own timeouts (preface 10 s,
header 10 s, idle 300 s, PING 20 s, drain 30 s), not the connection
deadlines above.
To turn it off:
server.http2.enabled: falseturns HTTP/2 off. The TLS listener then
offershttp/1.1only.server.http2.h2c: falseturns off h2c alone.
HTTP/2 client
Amber::HTTP2::Client is shaped like HTTP::Client (exec, get, post
and the rest, block forms, close) and runs on the same Mica core:
- Over Beryl TLS 1.3 it offers
h2andhttp/1.1in ALPN, and falls back
to HTTP/1.1 on the same socket when the server picks it.h2c: true
speaks prior-knowledge h2c. - One multiplexed connection per client honors the server's
MAX_CONCURRENT_STREAMS, with flow control both ways. - Refused streams, and streams above a GOAWAY's last stream id, are retried
on a new connection, only before any response headers reached the caller. - Connect, read, idle and an optional total request timeout; PING liveness;
a 64 MiB response limit by default (max_response_body_bytesize); decode
limits; gzip, deflate and Brotli decoding. - Over HTTP/1.1, at most 32 connections per client by default
(max_http1_connections). - Its errors are named, under
Client::Error < IO::Error.
CBOR and COSE
- Typed CBOR.
Amber::Schema::CBOR::Serializabledecodes and encodes a
type field by field. It honors theJSON::FieldandJSON::Serializable
options the type already carries (Strictandafter_initialize
included) and refuses the rest at compile time. - COSE object API.
Amber::Schema::COSE.seal_objectseals a document
(Hash(String, JSON::Any)) as CBOR, and.decrypt_objectopens one
straight back to it. - COSE in data-independent timing. Seal and open run on Beryl's
key-direct ChaCha20-Poly1305. Plaintexts and ciphertexts kept on the stack
are wiped after use. The wire format is unchanged: earlier messages open,
and a parsed message serializes back to the same bytes. respond_withwrites CBOR and COSE straight to the response, with a
Content-Length.- The CBOR reader builds each text string once and pools repeated map keys,
and the encoder writes each value into one buffer. Every bound and
rejection of the earlier reader stays.
Mica and Beryl are shard dependencies
Amber depends on the tagged Mica 0.4.0 and Beryl 0.2.6 shards, pinned by
commit and checksum in shard.lock, instead of carrying copies under
src/amber/vendor. The namespaces Amber::Mica and Amber::Beryl are gone;
code that named them uses Mica and Beryl. An app with Amber, Grant and
asset_pipeline installs one Mica and one Beryl. An app that requires a Mica
component itself lists mica at Amber's exact version.
Routing
-
Route audit.
Amber::Router::RouteAudit::AuditRouteTablereads the
real route tree and reports each finding with the file and line that drew
the route.- Errors: duplicate, shadowed and never-matching routes.
- Warnings: routes it cannot prove reachable, ambiguous overlaps,
redundant HEAD and OPTIONS routes, and parameter rules the router
ignores.
amber routes --checkruns it, and exits 1 on an error or 2 when the
audit cannot run. It ships with the next Amber CLI release; 2.0.21 does
not have it. -
Glob routes. A route drawn below a glob is no longer hidden by an
earlier route whose tail does not fit. Withget "/*h/b"drawn before
get "/*h/b/a", a request for/x/b/anow finds the second route.
Request bodies
JSON and other document bodies are read through an 8 KiB buffer on the
fiber stack, instead of a fresh 64 KiB heap buffer per request. On an M4
Mac mini, the schema-validated JSON benchmark went from 33-57 to 18-21
microseconds of server CPU per request. Limits and their errors are
unchanged.
The request path is back to Round 27's allocation (#1514). A JSON request
allocates 527 bytes less than in Round 27:
- The query-string limit scan is skipped when the query is empty.
- Accept is scanned in place.
- A body that fits the 8 KiB stack buffer becomes the result directly.
- The content-type and e-mail checks work in place.
Behavior and every parameter limit are unchanged.
Upgrading
Use Amber CLI 2.0.21 for new apps. It writes 2.0.0-beta.17; to move a new
or existing app to this beta:
- Set
version: 2.0.0-beta.18foramberinshard.yml. - Run
minecart update amber. - Run
minecart install --frozenfrom then on.
An app that uses MySQL moves to crystal-mysql 0.20.0 in the same step.
crystal-mysql 0.19.0 pins Beryl 0.2.5, and this beta requires Beryl 0.2.6,
so Minecart cannot resolve the two together; 0.20.0 requires Beryl 0.2.6.
In shard.yml, pin mysql (github: crimson-knight/crystal-mysql) to
commit: df3572c7f37b58a857d78fa5779a7bf46f2f2033 # 0.20.0, then run
minecart update amber mysql. Apps on PostgreSQL or SQLite need no other
change.
An app on 2.0.0-beta.17 that sets none of the new keys changes in these ways:
- HTTP/2 is on. Over TLS the listener offers
h2first in ALPN, so
browsers move to HTTP/2. A plaintext or UNIX-socket connection that opens
with the HTTP/2 preface is served as h2c. Those connections run under
server.http2's own timeouts. To stay on HTTP/1.1, set
server.http2.enabled: false; to turn off h2c alone, set
server.http2.h2c: false. - The default ALPN list is now
h2, thenhttp/1.1. In beta.17,
Amber::TLS::BerylBackend.server_context(key_file, cert_file)and
bind_listeneralways offeredhttp/1.1. The same calls now offerh2
first. Code that builds its own TLS listener with them and binds it to a
plainHTTP::Servermust passAmber::TLS::LIST_OF_HTTP1_ALPN_PROTOCOLS
as the ALPN list, or browsers agree on HTTP/2 with a server that cannot
speak it. Both methods also take the new TLS settings as keyword
arguments (ssl_settings:,listen_backlog:). - Every listener asks for a backlog of 4,096 instead of 128. Set
server.listen_backlog: 128for the old value. respond_withsends CBOR and COSE responses with a Content-Length.- The server logs one more line at start, with its connection settings.
server.sslis validated at start. Its defaults pass.
Code that named Amber::Mica or Amber::Beryl moves to Mica and Beryl,
and requires mica/http2, mica/deflate, mica/brotli, beryl/crypto or
beryl as needed.
To adopt the tuned connection values before the CLI writes them, add these
under server: in each config/environments/*.yml:
max_connections: 3000request_head_timeout_seconds: 10request_body_timeout_seconds: 30write_timeout_seconds: 30keep_alive_timeout_seconds: 60
Checks at the tagged commit
The tagged commit is the merge of amber#1516. That PR's head, 23b23d3, passed GitHub Actions run 47408348861 (8 jobs, crystal-alpha included) and CircleCI v2-beta. The merge commit has the same tree as the tested head. On the merge commit itself, run 47412091141 (8 jobs; the macOS job ran again after GitHub canceled it for want of a runner) and CircleCI v2-beta are green. Release notes: RELEASE_NOTES_V2_BETA18.md at the tag.
Commit: 7e99952cc5c3643c0c40e947824df8856bb6ec1a
Tree: d048c5710b70a87d15e541ab4d9454f74eb95b67
Tarball: amber-2.0.0-beta.18.tar.gz (git archive --format=tar.gz --prefix=amber-2.0.0-beta.18/ 7e99952cc5c3643c0c40e947824df8856bb6ec1a)
Tarball sha256: a0918497f35e2dafbbe535c2e4411d4aef3f2811b4ac8b2032fcaa38b1b9ead4
shard.lock checksum (Minecart 2025.11.25.9 and newer): sha256-v2:60abb0e19283fd4c1d86257ceea0f0d35160c152ee9cf7a3ad97b78770266aec
The tarball was built from the commit twice with git archive and once more with scripts/release_checksums.sh v2.0.0-beta.18, and all three gave the same sha256. The copy attached here was downloaded again after upload and matched. Minecart recorded the same sha256-v2 checksum for the commit on two machines.
| Ships with | Version | Commit | Release |
|---|---|---|---|
| Mica | 0.4.0 | 36badd67f0ef3ebad632b0a5e53262af9ffe3deb |
v0.4.0 |
| Beryl | 0.2.6 | d3c04cfb1764992cbffbda6f6c48fa83e8724464 |
v0.2.6 |
| crystal-mysql | 0.20.0 | df3572c7f37b58a857d78fa5779a7bf46f2f2033 |
v0.20.0 |
| Amber CLI | 2.0.21 (still pins 2.0.0-beta.17; the CLI release that pins this beta follows) | b70496c5e0e2e7932239fcdca91ff47c975070cf |
v2.0.21 |
Verification
Tag: v2.0.0-beta.18 (annotated tag object 52d0afe832aa7f1a0acadb39825baf723fee5d0c)
Commit: 7e99952cc5c3643c0c40e947824df8856bb6ec1a
Tree: d048c5710b70a87d15e541ab4d9454f74eb95b67
Release asset amber-2.0.0-beta.18.tar.gz sha256: a0918497f35e2dafbbe535c2e4411d4aef3f2811b4ac8b2032fcaa38b1b9ead4 (built three times, equal; downloaded again after upload, equal; sidecar amber-2.0.0-beta.18.tar.gz.sha256 equal)
GitHub source archive https://github.com/amberframework/amber/archive/refs/tags/v2.0.0-beta.18.tar.gz sha256: df8da62a0787fd1dc75eb95d66ee01d9c412b414d8dd183bdd430115d2689a5d (downloaded twice, equal; git get-tar-commit-id 7e99952cc5c3643c0c40e947824df8856bb6ec1a)
shard.lock checksum: sha256-v2:60abb0e19283fd4c1d86257ceea0f0d35160c152ee9cf7a3ad97b78770266aec