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

Release v0.4.0

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:

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

The repair at a glance

src/demo.unadiff
  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 unit

Failing example

ita.unauna
ita demo
  version 0.1.0
  edition 0.4
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
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

Fixed example

ita.unauna
ita demo
  version 0.1.0
  edition 0.4
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
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 tax = price(n + 1)
  @server.reply(to: exchange.right, reply: Reply(status: 200, headers: [], body: "{total + tax}"))
    if error use unit