Home / Docs / Diagnostics
U3033: An operation of HttpServer in the effect set of a together branch, a together for body, a first of branch, or handle or on_stop of a serve module
An operation of HttpServer is in the effect set of a branch of together, a body of together for or a branch of first of, or handle or on_stop of a serve module names HttpServer in its uses.
Why Una rejects it
The branches of together, the bodies of together for and the branches of first of run at once and act for the one task that runs the construct (spec/19 §1, spec/27 §6). A reply right of HttpServer is held by one task at a time (ADR 0123 rule 4), so two branches that could both answer it would answer in an order that timing decides.
The effect set of a branch therefore MUST NOT contain an operation of HttpServer: next, reply or close (spec/31 §1, ADR 0123 rule 5). This holds for an operation performed:
- in the branch;
- by a function it calls or names;
- by a function value whose type's requirements hold
HttpServer; - by a handler it installs;
- by an operation whose handler can perform one;
- or, in a program that imports a name of the server, by a
uses ofparameter that it calls or passes on, whose code its callers choose.
The error is at the operation, the call, the function value or the installation.
The same holds for handle and on_stop of the module that the serve section of ita.una names (spec/31 §7, ADR 0123 rule 16). In that form the host owns every exchange and answers each request with the reply handle returns, so neither function may name HttpServer, or a capability whose handlers can perform one of its operations, in its uses. The error is at the binding.
How to fix it
- In a branch, the repair is to compute in the branches and to answer after the construct.
- In
handleandon_stop, the repair is to return the reply fromhandle, or to write the server in the language form, withnextin afor everloop and noservesection.
The repair at a glance
module demo
import std.host (Exchange, HttpServer, Reply)
price(n: internal Int) -> internal Int = n * 3
answer(exchange: internal Exchange, n: internal Int) -> Unit
uses @server: HttpServer[reply]
=
together
let total = price(n)
- let sent = @server.reply(to: exchange.right, reply: Reply(status: 204, headers: [], body: ""))
- if error use unit
- unit
+ let tax = price(n + 1)
+ @server.reply(to: exchange.right, reply: Reply(status: 200, headers: [], body: "{total + tax}"))
+ if error use unitFailing example
ita demo
version 0.1.0
edition 0.4lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0module demo
import std.host (Exchange, HttpServer, Reply)
price(n: internal Int) -> internal Int = n * 3
answer(exchange: internal Exchange, n: internal Int) -> Unit
uses @server: HttpServer[reply]
=
together
let total = price(n)
let sent = @server.reply(to: exchange.right, reply: Reply(status: 204, headers: [], body: ""))
if error use unit
unitFixed example
ita demo
version 0.1.0
edition 0.4lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0module demo
import std.host (Exchange, HttpServer, Reply)
price(n: internal Int) -> internal Int = n * 3
answer(exchange: internal Exchange, n: internal Int) -> Unit
uses @server: HttpServer[reply]
=
together
let total = price(n)
let tax = price(n + 1)
@server.reply(to: exchange.right, reply: Reply(status: 200, headers: [], body: "{total + tax}"))
if error use unit