-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Handle :EXIT messages in ingestion WriteBuffer #6454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SAY-5
wants to merge
5
commits into
plausible:master
Choose a base branch
from
SAY-5:fix-writebuffer-exit-trap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bca05de
Handle :EXIT messages in ingestion WriteBuffer to prevent crash
SAY-5 ef30baa
Merge branch 'master' into fix-writebuffer-exit-trap
SAY-5 01c9985
Merge 57ec8f28e50651b53e963361220e52cffb5f8d54 into fix-writebuffer-e…
SAY-5 9a06340
Merge branch 'master' into fix-writebuffer-exit-trap
SAY-5 da23d41
test: trigger real linked-process :EXIT in write buffer test
SAY-5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| defmodule Plausible.Ingestion.WriteBufferTest do | ||
| use ExUnit.Case, async: true | ||
|
|
||
| alias Plausible.Ingestion.WriteBuffer | ||
|
|
||
| @opts WriteBuffer.compile_time_prepare(Plausible.ClickhouseEventV2) | ||
|
|
||
| test "keeps running when a linked process exits while trapping exits" do | ||
| opts = | ||
| @opts | ||
| |> Map.take([:header, :insert_sql, :insert_opts]) | ||
| |> Map.to_list() | ||
| |> Keyword.put(:name, :"write_buffer_exit_#{System.unique_integer([:positive])}") | ||
| # large interval so the empty buffer never flushes to ClickHouse during the test | ||
| |> Keyword.put(:flush_interval_ms, 60_000) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about making this a bit more readable? Since Something like: test "...", %{test: test} do
opts = [
header: @compile_time_opts.header,
insert_sql: @compile_time_opts.insert_sql,
insert_opts: @compile_time_opts.insert_opts,
name: test, # unique atom is at our disposal already
flush_interval_ms: 1_000_000_000 # no need to ever flush automatically on slow CI
]
|
||
|
|
||
| {:ok, pid} = WriteBuffer.start_link(opts) | ||
|
|
||
| # The buffer traps exits, so a linked process exiting delivers a real | ||
| # {:EXIT, from, reason} message to handle_info/2. Linking a throwaway | ||
| # process to the buffer and killing it reproduces the crash in #6382 | ||
| # without sending a synthetic message. | ||
| child = | ||
| spawn(fn -> | ||
| Process.link(pid) | ||
| Process.sleep(:infinity) | ||
| end) | ||
|
|
||
| ref = Process.monitor(child) | ||
| Process.exit(child, :shutdown) | ||
| assert_receive {:DOWN, ^ref, :process, ^child, _}, 1_000 | ||
|
|
||
| assert Process.alive?(pid) | ||
| assert WriteBuffer.flush(opts[:name]) == :ok | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is unnecessary, let's log the reason instead (
warninglevel is fine).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonus points for asserting the log entry in test 🤗