16. Troubleshooting

Start with these three commands; most problems show up in one of them:

# emfor check-config                       # is the config valid?
# emfor status                             # is the daemon running, what does it see?
# emfor lookup <service> --explain         # why does a lookup answer what it answers?

and the log: journalctl -u emfor (systemd) or syslog with the tag emfor (FreeBSD). The emfor messages below were produced by emfor 0.7.0 in a Debian test container, except the reasons of plugins, which come from the code, and the systemd and DNS symptoms, which come from the repository’s documents.

The daemon does not start

MessageCauseFix
cannot open state store: /var/lib/emfor/state.mdb.writer: No such file or directory (os error 2)The store directory does not exist; the daemon does not create it.install -d -o emfor -g emfor -m 0755 /var/lib/emfor (the unit’s StateDirectory= does this).
cannot open state store: store is already in use by another emfor daemon: lock file /var/lib/emfor/state.mdb.writer is heldAnother daemon uses the store.Stop it, or give this one another [store] path.
cannot start metrics server: cannot listen on 127.0.0.1:8080 (tcp): Address already in use (os error 98)The port is taken.Free it or change listen.
emfor status prints store is empty: the daemon has not written to it yet; if it should be running, check its logThe daemon opened the store and exited before its first write, for example because it could not bind its DNS port. The store is not damaged.Read the log (journalctl -u emfor) for the error the daemon exited with; the rows above and the port in [dns] listen are the usual causes.
invalid config /etc/emfor/emfor.toml: 2 error(s) and the error linesInvalid config (exit 2).Run emfor check-config and fix each line (below).
/etc/emfor/conf.d: writable by group or others (mode 0775); refusing to load it; to fix it: chmod g-w,o-w /etc/emfor/conf.dA config file or directory others can change.Run the chmod (or chown) the message names.
include_dir: cannot read directory /etc/emfor/conf.d: No such file or directory (os error 2)include_dir names a missing directory.Create it, or remove include_dir.
--check-config was replaced by "emfor check-config"An old command line.Use emfor check-config.
systemd: the unit is failed after repeated startsFive failed starts in a minute (StartLimitBurst=5).Fix the cause, then systemctl reset-failed emfor.

Config errors

emfor check-config prints one line per error, prefixed by the key’s path and, for a conf.d file, followed by the file:

services."web.svc.emfor".timeout: timeout must not exceed interval (in /etc/emfor/conf.d/50-x.toml)
MessageFix
defaults.interval: invalid duration "2", use e.g. "500ms" or "2s"A duration needs a unit.
defaults.jitter: jitter above 50% or below 0%jitter is "0%"–"50%".
services.Bad_Name: invalid service name: labels of [a-z0-9-], 1-63 characters each, 253 characters totalLower-case DNS-style names only.
backend "web1:80" must be an IP literal with port: IPv4:port or [IPv6]:port, port 1-65535Backends are IP addresses, never host names.
duplicate backend "10.0.0.1:80"Each backend once per service.
weight must be from 1 to 100
at least one backend must not be a backup
unknown checker `nope`check names neither a built-in check nor a declared plugin.
check_options.bogus: unknown keyA typo, or an option of another check.
path: must start with '/'http path.
expect_status[0]: status 700 outside 100-599
tls_verify: requires tls = truetcp TLS keys need tls = true.
expect: required when send is settcp.
command: "check.sh" is not an absolute pathexec and plugin commands are absolute.
env_pass: EMFOR_IP is set by emforDo not list EMFOR_IP, EMFOR_PORT, EMFOR_SERVICE.
site: invalid site label: 1-63 characters of [a-z0-9-], not starting or ending with -
/etc/emfor/conf.d/60-s.toml: store is only allowed in the main config file[store] and include_dir belong in the main file.
/etc/emfor/conf.d/70-b.toml:1:24: invalid TOML: unclosed table, expected ']'TOML syntax; line and column are given.

A reload did not take effect

A reload is all or nothing. The log says:

ERROR emfor_daemon::cli: invalid config /etc/emfor/emfor.toml: 2 error(s)
...
reload rejected; keeping the previous config

Some settings are never reloaded: store: store settings require restart, dns.listen: dns listen settings require restart, and the same for metrics.listen and peers.listen. Restart for those.

Every lookup fails

ErrorCauseFix
UNAVAILABLE: store /var/lib/emfor/state.mdb does not exist; is the emfor daemon running?The daemon has never run, or EMFOR_STORE points elsewhere.Start the daemon; check [store] path against EMFOR_STORE.
UNAVAILABLE: cannot open store /var/lib/emfor/state.mdb: Permission deniedThe application’s user cannot read the store or write the lock file.Add it to the daemon’s group (chapter 12) and restart the application.
UNAVAILABLE: EMFOR_MAX_STALENESS="3" is invalid: ...The variable needs a unit.EMFOR_MAX_STALENESS=3s.
UNAVAILABLE saying the LMDB format differsThe client comes from another release.Install clients from the daemon’s release.
INCOMPATIBLEA client older than the store’s format (a client before 0.4 on a version 2 store), or a record the client cannot parse (damage, or a bug worth reporting).Upgrade the client; if it is from the daemon’s release, report it.
NOT_FOUND: no service named "nope.svc.emfor"A typo, or the service is not in this host’s config.emfor status lists the services.

emfor status shows the same problems from the command line: cannot open store /var/lib/emfor/state.mdb: no such file and cannot open store ...: Permission denied (os error 13) (exit 2).

A service is ALL DOWN

ALL_DOWN: service db.svc.emfor: no backend is healthy, and on_all_down is closed
  1. emfor status --service db.svc.emfor shows each backend’s reason.
  2. emfor lookup db.svc.emfor --explain shows why each one is out; every backend drained also gives ALL_DOWN.
  3. If the message says the store is stale (emfor daemon not updating it), the backends are not the problem: the daemon is. emfor status then says daemon: stale, heartbeat 4.5s ago or daemon: stopped.
  4. Run the check by hand from the same host (curl, nc, the exec program as the daemon’s user).

Reading the reasons

ReasonFromMeaning
Connection refused (os error 111)tcpNothing listens on the port.
timeoutanyNo answer within timeout.
expect: got "..."tcpThe answer did not match expect.
error sending request: client error (Connect): tcp connect error: Connection refused (os error 111)httpNothing listens.
unexpected status 503httpThe status is not in expect_status.
cannot build http client: ...; https checks need the system CA certificates, or a ca_file, unless tls_verify = falsehttp (error)Install ca-certificates, point ca_file at your private CA, or set tls_verify = false.
exit code 1, or the program’s first output lineexecThe check program said down.
cannot run /path: ...exec (error)Not found, not executable, or not allowed under the unit’s sandbox.
killed by signal 9execThe program crashed or was killed.
connect: Connection refused (os error 111)emfor-check plugins
plugin <name> unavailable, plugin exitedplugin (error)The plugin crashed or is restarting; see the log.
plugin <name> busy: it is not reading its requestsplugin (error)The plugin stopped reading; it is restarted after 3 unanswered requests.
password_file: ...plugin (error)The daemon’s user cannot read the file.
peers 2/3: <reason>peer groupTwo of three assigned checkers saw it down.
local: <reason>peer groupThis host saw it down; the votes did not.
drainedstoredrain = true (chapter 8).
check task restarted (in the history)daemonA check task stopped and was restarted. Look for check task of backend ... stopped in the log and report it.

An error never marks a backend down, but nothing but errors for fall × interval takes it back to unknown.

A backend flaps

FLAPPING (5 changes in 10m) in emfor status, or the EmforBackendFlapping alert, means frequent changes. Usually the timeout is close to the backend’s normal response time, or the backend is overloaded. emfor status --history --service <name> shows when and why. Raise timeout (at most interval), raise fall and rise, or fix the backend.

Checks work by hand but not in emfor

  • The environment. Since 0.7.0 check programs get only PATH, LANG, TZ and LC_*. Add what they need to env_pass.
  • The user. The daemon runs as emfor; run the check with runuser -u emfor -- ....
  • The sandbox. The unit makes the file system read-only and hides other processes; a check that writes a file or reads /home fails there.
  • Redirects. http checks do not follow them, and a 301 is inside the default 200-399, so a redirect counts as up. Set expect_status = ["200"] (or point path at the final page) to require it.
  • Proxies. http checks ignore http_proxy.

DNS does not resolve

SymptomCauseFix
No answer at allNo [dns] table, the daemon is down, or the wrong port.dig @127.0.0.1 -p 5300 <service>.
REFUSEDThe name is outside the zone.Check [dns] zone.
NXDOMAINNo such service, or it was just added (negative caching for ttl).emfor status.
SERVFAILAll down and closed, every backend drained, the daemon just started, or a validating unbound without domain-insecure.emfor lookup <service> --explain.
Works with dig @127.0.0.1 -p 5300, not with getent hostsThe host resolver does not forward the zone.Chapter 10.
A failed backend is still returnedResolver or runtime caching.Chapter 10.

The store looks stale while the daemon runs

  • emfor_store_commit_failures_total rises, MDB_MAP_FULL in the log: the store is full. Raise [store] map_size and restart.
  • The host’s clock jumped, in either direction: clients compare the heartbeat with their own clock. A heartbeat more than EMFOR_MAX_STALENESS ahead counts as stale too; emfor status then says heartbeat <age> in the future. It clears by itself within about a second of the next heartbeat. The daemon writes a clock_jumped warning and counts it in emfor_clock_jumps_total when its own clock jumped by more than 2 seconds (chapter 12).
  • The daemon is overloaded or stopped (SIGSTOP, a debugger).

The lock file is owned by another user

If <store>-lock was deleted while applications ran, the first process to open the store recreated it with its own owner, and the daemon may then fail to start. Stop the applications, or chown emfor:emfor and chmod 0660 the lock file, then start the daemon. Never delete the lock file alone.

A denial from SELinux or AppArmor

emfor ships no policy (chapter 13), so this applies when you or your distribution added one; on Rocky Linux 9 with the targeted policy and on Ubuntu 24.04 the daemon is not confined and raised no denial. The signs: a check or the daemon fails with Permission denied although the file modes, the owner and the unit’s sandbox look right, and the same thing works with the policy off. The commands below are the usual tools; getenforce and ausearch were run against emfor on Rocky Linux 9, and the kernel log was searched for apparmor="DENIED" on Ubuntu 24.04.

# getenforce                                  # SELinux: Enforcing or Permissive
# ausearch -m AVC,USER_AVC -ts recent         # SELinux denials
# aa-status                                   # AppArmor: loaded profiles
# journalctl -k | grep 'apparmor="DENIED"'    # AppArmor denials
  1. Find the denial and note the program, the path or port and the operation.
  2. Confirm the policy is the cause: put it in permissive mode for a moment (setenforce 0, or aa-complain on the profile), repeat the failing action, and switch it back.
  3. Allow exactly that access in the policy, not a wider one. For a store under another directory, give that directory the same label as /var/lib/emfor (SELinux) or add its path to the profile, and set ReadWritePaths= in the unit (chapter 4).

A check that starts a program (exec, a plugin) fails with a denial when the policy does not allow that program to run from the daemon’s domain.

Peer problems

SymptomCause
emfor_peer_messages_rejected_total{reason="auth"} risesMembers have different secrets, or one restarted during a secret change (chapter 11).
reason="plaintext"A member sends EMP1 (encrypt = false) to one that refuses it.
reason="sender"A message from an address that is not in members (NAT, a wrong listen).
reason="site"A member with another site.
reason="stale" or replayClocks differ by more than 5 seconds in either direction (chapter 11), or messages are duplicated on the way. For stale, emfor status shows peers: clock of <member> is <n.n> s behind this host from 2 seconds on, and emfor_peer_clock_offset_seconds the offset of each member; when one line says that the clock of this host differs from every member, fix this host’s clock first.
peers: 1/2 live, ... too few live members to voteFewer than three live members: no votes, each decides alone.
A digest mismatch in emfor status --jsonMembers check a service differently (options, timeout, plugin command, env_pass).
peers: no results from <member> for <service> in emfor status, or emfor_peer_silent_checkers above 0That member is an assigned checker but sends no results for the backend: it lacks the service or the backend, its check keeps giving error, or its packets do not reach this host (chapter 11). Compare the services and backend lists of the members.
local-up in emfor statusDown by votes but up here: a network path from this host only, or a different check.
Built with Hugo
Theme Stack designed by Jimmy