server: handlers defined after `serve!` starts fail with a world-age error on 2.x

Open
#1,515 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
julia
Domain
api, backend

Research direction

Read the HTTP 1.x handler call in src/Servers.jl and compare it with the HTTP 2.x server path. Start by reproducing the late registration example against a running Router, then inspect the server handler tests. Done means the late route and a handler redefined under Revise return successful responses without a world-age error.

Written by the indexing model from the issue text.

Description

Claude:


HTTP 1.x calls server handlers through Base.invokelatest ("makes live-editing handlers more Revise friendly", src/Servers.jl). HTTP 2.x doesn't: there is no invokelatest in src, so a handler defined after serve! starts is too new for the server task's world age.

This breaks routes registered on a running Router, and redefining a handler under Revise.

using HTTP
router = HTTP.Router()
HTTP.register!(router, "GET", "/early", req -> HTTP.Response(200))
srv = HTTP.serve!(router, "127.0.0.1", 38123)
HTTP.register!(router, "GET", "/late", req -> HTTP.Response(200))
HTTP.get("http://127.0.0.1:38123/late"; status_exception=false).status
  • HTTP 1.11.1: 200
  • HTTP 2.12.3 (Julia 1.13.3): 500, logged as
┌ Error: server handler error
│   exception =
│    MethodError: no method matching (::var"#5#6")(::HTTP.Request{HTTP.EmptyBody})
│    The applicable method may be too new: running in world age 39321, while current world is 39323.

The workaround is serve!(req -> Base.invokelatest(router, req), ...). Found in JuliaCI/PkgEvalFarm.jl#86, whose test stub server broke when it moved to HTTP 2.

Written with Claude Code (Opus 5.5).

Dominant language
Julia
Stars
688
Forks
196
Avg merge
5h 59m
Merged PRs (30d)
148

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaWeb/HTTP.jl

All issues in JuliaWeb/HTTP.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.