Upgrading

View Source

This page tells you what to change in your code when you move to a newer release. Read it before each upgrade. The changelog lists everything that changed; this page lists only the changes that can break your code, and what to write instead. Releases are newest first. A release that is not on this page needs no change in your code.

0.15.0

Components.

what changedwhat to change
wasm_component:call/4, call_async/4 and start_async/4 check each argument against its descriptor first, and refuse one that does not fit with {error, #{class := invalid, kind := bad_argument}}. An integer out of the range of its width used to be cut to that width (256 as a u8 reached the guest as 0), and a char or a string went in uncheckedpass values in their type's range, chars that are Unicode scalar values and strings of valid UTF-8; to find which argument was wrong, read path in the error's ctx
a variant, enum or flag name the type does not declare is bad_argument. It used to be a trap with kind unknown_casematch bad_argument instead of unknown_case
an argument of the wrong Erlang type, such as an atom for a u32, is bad_argument. It used to be malformed / internalmatch bad_argument
a value a host function returns to the guest is checked the same way, and one that does not fit traps the call with kind host_error. It used to be cut to its width, or lowered as it wasreturn values that fit the result type of your host function: a u32 from 0 to 16#FFFFFFFF, a valid UTF-8 binary for a string

WASI files. Your Erlang code needs no change for these, but a guest you run sees different answers. Make writes durable has what each call does now.

what changedwhat to change
the sync open flags are refused: DSYNC, RSYNC and SYNC in path_open and fd_fdstat_set_flags answer ENOTSUP, and file-integrity-sync, data-integrity-sync and requested-write-sync in open-at answer unsupported in 0.2 and 0.3. They used to be accepted while every write went on as beforebuild the guest to open its files without these flags, and to call fd_sync, fd_datasync, sync or sync-data after the writes that must survive a power loss
fd_sync and fd_datasync answer EBADF for a descriptor that is not open and ENOTCAPABLE for one without the FD_SYNC or FD_DATASYNC right, and a read preopen gives neither right. They used to answer ESUCCESS and sync nothinggrant a directory with write when the guest syncs files in it
a sync the filesystem cannot make answers its error. It used to answer ESUCCESSnothing, unless the guest treats every failed sync as fatal: then run it on a filesystem that can sync
without the NIF, a sync of a directory answers ENOTSUP, or unsupported in 0.2 and 0.3. It used to answer success and sync nothingbuild the NIF if a guest syncs directories and must not fail; see The file NIF
fd_advise answers EBADF for a descriptor that is not an open file and ENOTCAPABLE for one without the FD_ADVISE right. It used to answer ESUCCESS for any descriptornothing, for a guest that gives advice only on files it opened

Dependencies.

what changedwhat to change
the runtime requires erlang_h1 0.14 and h2 0.19.1, where it required 0.11 and 0.18if your project pins either itself, move it to ~> 0.14.0 and ~> 0.19.1

0.10.0

Network and HTTP.

what changedwhat to change
wasi_http_listener:start/1 listens on 127.0.0.1 unless you say otherwise. It used to listen on every interfaceto accept connections from other machines, add ip => {0, 0, 0, 0} to its options
the listener answers 408 to a request body that takes more than request_timeout (60 s), 413 to one over max_body_bytes (8 MiB), and 504 when the guest is still running at the deadlinepass larger request_timeout or max_body_bytes values to wasi_http_listener:start/1 if your requests need them
every HTTP body the host holds is limited to 8 MiB, and a larger response a guest receives fails with HTTP-response-body-sizepass http_max_body_bytes to wasi_preview2:command/1 and the other runners if your bodies are larger
a wasi:http request to a host name is checked against the addresses the name resolves toadd resolve => allow to the network grant of a guest that calls hosts by name
fuel, max_depth, max_memory_pages, max_heap_words and max_host_calls passed to wasi_preview2:run_serve/3, run_command/3 or a listener's serve_opts now apply. They were ignoredcheck that the values you pass are large enough for your guest
wasi_preview3:run_serve/3,4 answers {ok, Status, Headers, Body, Trailers} for a response that has trailersadd a clause for the 5-tuple; a response without trailers still gives the 4-tuple

Modules and the application.

what changedwhat to change
a module larger than max_module_bytes (64 MiB) is refused with module_too_largeset {wasm, [{max_module_bytes, Bytes}]} if you load larger modules
the module cache holds at most max_resident_module_bytes (2 GiB); past it a new load answers {error, {module_cache_full, Bytes}}unload modules you no longer use, or raise max_resident_module_bytes
after application:stop(wasm) and a new start, an instance made before the stop traps with runtime_stoppedmake your instances again after the application starts
wasm_instance_worker runs the module's start function with a deadline: timeout in the worker's limits, or worker_timeout (5 s)for a module whose start takes longer, set limits => (wasm_limits:untrusted())#{timeout => Ms}
in compiled code, a call_stack_exhausted trap has no depth in its ctxmatch on the kind, not on depth

Components and adapters.

what changedwhat to change
a WASI 0.3 import only binds a host key that ends in @0.3. It used to fall back to the 0.2 function of the same nameserve a 0.3 component with wasi_preview3, or name your own host keys with @0.3, such as wasi:cli/stdout@0.3
wasm_component:call_async/4 answers {error, async_backpressure} while the instance holds backpressurehandle that answer, for example by calling again later
an adapter's artifact/1 runs in a short-lived process, which exits after it returnsreturn values from artifact/1, not resources tied to that process, such as an ETS table or a link

0.9.1

what changedwhat to change
wasm_component:call/4 hands back an own resource as a small index into the instance's handle table, starting at 1. It used to be the guest's own representationtreat a handle as an opaque value: pass it back to the component, never read it as the guest's data
a handle that was dropped, never handed out, or is of another resource type answers a resource_not_live or resource_wrong_type trappass each handle only to the functions of its own resource type, and only while it is live
wasm_component:drop_resource/3 answers the destructor's result: ok, or the trap it raised. It used to answer ok alwaysmatch {error, _} as well as ok

0.9.0

what changedwhat to change
wasm:restore/3 no longer takes recycle, and the worker option recycle_idle is gone. Both are ignoredremove them: wasm:restore(Image, Bindings, #{recycle => true}) becomes wasm:restore(Image, Bindings, #{})
a restore or a memory write that the node page budget cannot afford is refused with exhaustion / memory_limit. A restore used to fail with malformed / internalmatch the new class and kind
the node page budget counts the pages a memory has allocated, in whole chunks: a three-page memory counts fourif you were close to wasm_engine:set_page_limit/1, raise the limit
workers built on py_reactor.wasm need the new buildrebuild it with scripts/build-python-reactor.sh, which now needs binaryen's wasm-opt, or WASM_OPT set to it
the CPython standard library ships precompiledafter you edit a .py file of the library, rebuild the reactor

0.6.0

what changedwhat to change
workers built on py_reactor.wasm need the new buildrebuild it with scripts/build-python-reactor.sh
the CPython reactor imports worker.context and worker.context_sizean adapter of your own over py_reactor.wasm must bind both imports
images of the previous reactor build are not restorednothing: the worker captures a new image the first time

From 0.3 to 0.4

This section is for you if you copied modules from examples/ in 0.3: the worker, the worker kernel, the reaper or a language adapter (the glossary defines each one). In 0.4 those modules are part of the application, with wasm_ names. Nothing you copied breaks: no new module has the same name as a module in the 0.3 examples/, so your copies still compile and run. Moving to the installed modules is optional, and you can move one module at a time.

Pick your case

you copieddo this
wasm_worker.erl, unchangedswitch the calls to wasm_instance_worker, below, and delete your copy
wasm_worker.erl, changedkeep it, or move to wasm_instance_worker if its options now cover your change
the kernel: script_worker, worker_reaper, script_v1, worker_error, an adapterswitch with the table below when you are ready

Switch the simple worker

wasm_instance_worker has exactly the calls of the 0.3 example: start_link/1,2, call/3,4, stop/1 and info/1, with the same options and the same return values. So you only rename the calls:

perl -pi -e 's/\bwasm_worker:/wasm_instance_worker:/g' $(grep -rlw wasm_worker src)

Then delete src/wasm_worker.erl. If your copy was renamed, as getting-started.md used to suggest, put your module's name in place of wasm_worker in that command.

Switch the kernel

0.3, copied0.4, installed
worker_reaper:start_link(#{scratch => Dir}) in your supervision treeremove it: the application runs the reaper. To keep recovery across node restarts, set {wasm, [{scratch_roots, #{scratch => Dir}}]}
worker_reaper:start_link(Roots, Settings){wasm, [{scratch_roots, Roots}, {reaper_options, Settings}]}
script_worker:start_link(Adapter, #{root => scratch, ...})wasm_script_worker:start_link(Adapter, #{...}); root defaults to scratch
js_worker:run(W, Src, Ctx), python_worker:run(W, Src, Ctx)wasm_script_worker:run(W, Src, Ctx)
qjs_adapter, qjs_reactor_adapterwasm_javascript_command, wasm_javascript
py_adapter, py_reactor_adapterwasm_python_command, wasm_python
lua_reactor_adapterwasm_lua
-behaviour(script_worker) in your own adapter-behaviour(wasm_worker_adapter); the callbacks are unchanged
worker_error:runtime(E) and the other constructorswasm_worker_error:runtime(E)
worker_reaper:stats/0, requests/0wasm_script_worker:cleanup_stats/0, cleanup_requests/0

Limits and option keys are otherwise unchanged. The script profile the shipped adapters speak (one source, a JSON context, main(context), a JSON result; not the compile profile option) is still called script_v1, and the boot scripts are still in priv/script_v1/, so a guest built for 0.3 needs nothing.

Where scratch files go now

Without scratch_roots, the reaper keeps request files in a directory that only this node uses, under the user cache directory. It removes that directory when the node stops cleanly. If the node crashes, the next start does not clean that directory, because the next start uses a new one. Set scratch_roots in production. When a node restarts, it finds and cleans what a crashed node left in the configured root. Only one node at a time may use a configured root.

Delete what you replaced

Remove the copies you no longer use, run your tests, and check that nothing still names them:

grep -rlwE 'script_worker|worker_reaper|script_v1|qjs_adapter|py_adapter' src

Read this next

The changelog.