Skip to main content

Hew 0.11.3 lets servers finish accepted requests

· 2 min read
v0.11.3

A client can be halfway through uploading a request when its server receives SIGTERM. In Hew 0.11.3 the standard HTTP server closes admission, lets the handler read the rest of the body and sends its response. An idle keep-alive connection closes immediately. A WebSocket server finishes a partially received message before it starts the closing handshake.

Returning from main also gives work already in the program time to finish. A queued actor turn can run, a sleeping task can wake, and a supervisor can complete an armed restart. When the work finishes, the runtime invokes the actors’ stop hooks.

Give a service time to stop

The runtime previously started a five-second drain when main returned. With the default signal handler, a deployment can set its own time limit. A service manager that allows 30 seconds for termination can give Hew 25 seconds to finish accepted work and leave five seconds for cleanup.

HEW_SHUTDOWN_WITHIN=25s ./server

When the program itself requests shutdown, use shutdown(within: 25s). The call returns immediately. At the deadline the runtime cancels unfinished work, reports what it cut and exits with status 1. Without a deadline an accepted socket read can wait for its peer to send the rest of the message.

Use os.wait_for_shutdown() when your code needs to observe the beginning of shutdown. Multiple tasks can wait, and a task that starts waiting after shutdown begins returns immediately. It works in a select arm, so a service can release an idle session while keeping another session’s transfer intact.

If you embed Hew from C, replace hew_shutdown_initiate with hew_shutdown_request(within_ns, code, has_code).

Actors that live for one request

A stopped or crashed unsupervised actor now releases its storage when terminal cleanup finishes. A server can keep accepting new clients without accumulating the storage of actors that served earlier ones. If another actor still holds a handle, stopped can report that actor’s terminal result. Independent actors running on different workers also avoid a shared lock on every message.

The release also improves numeric literal inference and reports local actor wait cycles through nested tasks and cleanup. See the Hew 0.11.3 release notes for the full changes and migration guidance.

Hew Notes

Language development, engineering articles, releases and community projects, about once a month, with an extra issue for a significant release. Written in English.

Subscribe to Hew Notes