Troubleshoot¶
This page lists common errors and symptoms, with their causes and fixes. Find the error or symptom that you see, and then apply the fix. Where another page explains the behavior in depth, the entry links to it.
Installation¶
hanami jobs or hanami sockets isn't a command¶
The gem isn't in the :cli group, and the hanami command loads only that group. To fix it, add
group: [:default, :cli] to the gem in your Gemfile, and then run bundle install.
hanami sockets install --backend=sql writes no migration¶
The command prints "mankai-sockets-sql is not loaded, so no migration was written."
mankai-sockets-sql isn't in the :cli group. To fix it, add group: [:default, :cli] to
mankai-sockets-sql in your Gemfile, run bundle install, and run the command again.
hanami jobs install says the backend needs no installation¶
The command prints "Backend sql needs no installation." mankai-jobs-sql isn't in the :cli
group. To fix it, add group: [:default, :cli] to mankai-jobs-sql in your Gemfile, run
bundle install, and run the command again.
Dry::Core::Container::KeyError for queue.enqueuer, cache, or sockets.endpoint¶
The provider isn't loaded. Check the following:
- The provider file is in
config/providers/. - The provider has the expected name. Jobs components use the provider's name:
queue.enqueuercomes fromregister_provider(:queue, ...). - The file
requires the gem at the top.
A boot warning about fractional_seconds, a busy handler, or the pool size¶
The database connection needs a setting that Mankai doesn't change for you. For each setting, see Prepare the database.
Jobs¶
Jobs are enqueued but never run¶
With the SQL backend, jobs run only in a worker process, which hanami jobs start starts. To fix
it, do the following:
- Add
worker: bundle exec hanami jobs starttoProcfile.dev, or start a worker in another terminal. - Check that the worker serves the job's queue. Mailer jobs use the
mailersqueue.
hanami jobs start raises UnsupportedError with "has no worker processes"¶
The provider uses the :memory, :inline, or :async backend. These backends run jobs inside the
process that enqueued them, so they have no worker. To run a worker, use the SQL backend. For how the
backends differ, see How jobs work.
A job fails once and isn't retried¶
Retries are off by default: a job's max_attempts setting is 1. To retry, raise max_attempts in
the job's config, or add retry_on rules. retry_later also counts against max_attempts. For
details, see Make jobs reliable.
An argument is missing inside #call¶
A job with a contract keeps only the keys that the contract declares. Declare every argument in
the contract, and use optional for optional ones. For details, see
Define and enqueue jobs.
Dry::Events::InvalidSubscriberError when you subscribe to mankai.jobs.* events¶
The events aren't registered until the queue provider starts. Subscribe in the provider's
after(:start) block. For details, see
Subscribe to job events.
Jobs show as failed with ProcessPrunedError or ProcessExitError¶
The worker process stopped or disappeared while it ran these jobs. These jobs don't follow retry
rules. To run them again, call Hanami.app["queue.backend"].retry_failed(ids). For details, see
Recover jobs from a lost worker.
Cache¶
Mankai::Cache::SerializationError when you cache a repository result¶
The cache can't serialize repository structs. Cache plain data instead, such as
book_repo.find(id)&.to_h. For what you can cache, see
How the cache works.
The block runs on every call¶
Your test environment might use the :null store, which never keeps a value. To fix it, use the
:memory store. Also check that the key and the version: option are the same on each call.
Mankai::Cache::InvalidKeyError from the view helper¶
An object in the key has no cache_key method. Add a cache_key method to the struct or part, or
build the key from plain values: cache ["v1", "books", book.id, book.updated_at]. For details, see
Cache data and views.
Dry::Events::InvalidSubscriberError when you subscribe to mankai.cache.* events¶
Use Symbol event names, such as :"mankai.cache.fetch", and subscribe in the cache provider's
after(:start) block.
WebSockets¶
ConfigurationError with "channel key ... is not registered"¶
No component matches a key in config.channels. For the key "channels.chat", check that
app/channels/chat.rb defines Bookshelf::Channels::Chat, where Bookshelf is your app's module.
ConfigurationError with "config.authenticator is required"¶
The provider has no authenticator and doesn't allow anonymous connections. Set
config.authenticator, or set config.allow_anonymous = true while you develop. For details, see
Authenticate connections.
The browser can't load mankai-sockets.js (404)¶
Hanami doesn't serve the public/ directory on its own. Import the client through hanami-assets, or
serve public/js with Rack::Static. For both options, see
Load the client.
The upgrade request fails before the connection opens¶
The server rejected the browser's request to open a WebSocket connection. Check the HTTP status in the browser's network tab, and then find it in the following table:
| Status | Cause and fix |
|---|---|
| 403 | The page's origin isn't in allowed_origins. Behind a proxy, check X-Forwarded-Proto and Host. |
| 426 | The request wasn't a WebSocket upgrade request. Check the URL and the proxy's upgrade headers. |
| 400 | The client didn't offer the mankai.sockets.v1 subprotocol. Use the Mankai browser client. |
| 501 | The server doesn't support Rack full hijack. Use Puma. |
The connection opens, then closes with code 4401 and doesn't reconnect¶
Authentication failed. One of the following happened:
- The authenticator returned
nil. - The session has no user. Check that sessions are enabled.
- The token is invalid or expired, or the app has no
token_secret.
A broadcast from the console or a job never reaches the browser¶
The :memory backend reaches only browsers connected to the same process. To broadcast across
processes, use mankai-sockets-sql. For details, see
Broadcast across processes.
The browser client's perform rejects with "not connected"¶
The client sent a message before the connection opened. Call perform only after the consumer's
connected callback runs. For details, see Use the browser client.
For every close code, see Close codes in the protocol reference.