barrelltechgh

barrelltechgh

I have a Broadway Pipeline with a custom producer that is just using postgres to store tasks in normal table.

When I restart my application, I’m losing access to MyApp.Repo in different ways. Sometimes individual Processors cannot write to the database, but they will get acknowledged fine. Other times, acknowledgements will get lost. No matter what always with errors:

[error]
[info] Postgrex.Protocol (#PID<0.3666.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.4048.0> exited

This makes sense why it’s happening — MyApp.Repo is getting shut down prior to MyApp.Pipeline. However, MyApp.Repo comes before MyApp.Pipeline in my supervision tree, so I’m not sure what the issue is. I assume this is because it takes time to drain the messages, but that doesn’t help me much in finding a solution.

I imagine there is something incredibly simple I can do with OTP to resolve this, but I’m unsure of what. My current attempt is to add the following to my application.ex

@impl true
def prep_stop(state) do
  :ok = Broadway.stop(MyApp.Pipeline, :shutdown)
  state
end

but based on how little information I can find on the prep_stop callback, I’m assuming this is not the best OTP way to go about things.

Showing Posts 1 to 3

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

If what you’re saying is your tree looks like:

[
...
YourApp.Repo,
...
Broadway
]

Then that should work properly. Children are shut down in reverse order of boot, and the shutdown process is synchronous. That is a to say that the Broadway pipeline should be totally shutdown by then.

Is there any extra task spawning or async work you’re doing in the broadway pipeline that might leave processes floating around?

barrelltechgh

barrelltechgh OP

Correct, that is what my tree looks like (although I’m not requiring the Broadway module in my supervision tree, but MyApp.Pipeline, where MyApp.Pipeline starts with use Broadway).

I’m not doing anything too crazy in the pipeline (at least not task wise). Most of them are API requests. There are some messages that use FLAME, but this error happens on all messages. When a restart occurs during a FLAME call, the FLAME machines err appropriately, the messages fail, get acked, then the ack fails due to Postgres being disconnected:

The issue occurs regardless of the task contents though

EDIT: It should be noted that these 4 failures in particular are because of application defined above MyApp.Pipeline all terminating before Broadway can drain.

barrelltechgh

barrelltechgh OP

UPDATE: Many iterations later, and I believe I was able to resolve it by extending the kill_timeout configuration setting in my fly.toml. So the top of my fly.config.toml file looks like:

app = "my-app"
kill_signal = "SIGTERM"
kill_timeout = 300

300 (seconds) is the maximum value on fly, the default value is 5 (seconds).

Will report back if I notice it regress!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews