Handle :EXIT messages in ingestion WriteBuffer#6454
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Thanks for your contribution. With regards to the test, it seems a bit pointless to send a message to an artificially spawned buffer - you could do that against the primary buffer as well, since nothing is expected to happen - except no crash. You could experiment with triggering sending the actual But the PR states that this is ClickHouse socket dying - in which case |
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Good points, thanks. I reworked the test to spawn a process, link it to the buffer, and kill it, so the buffer now receives a genuine On the second point: you're right that the socket dying is a separate failure mode. The buffer isn't linked to the ClickHouse connection ( |
aerosol
left a comment
There was a problem hiding this comment.
One last round of changes if you don't mind and we're good to go
| end | ||
|
|
||
| def handle_info({:EXIT, _from, _reason}, state) do | ||
| # We trap exits so terminate/2 can flush on shutdown. Linked ports and |
There was a problem hiding this comment.
This comment is unnecessary, let's log the reason instead (warning level is fine).
There was a problem hiding this comment.
Bonus points for asserting the log entry in test 🤗
| |> 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) |
There was a problem hiding this comment.
What do you think about making this a bit more readable? Since compile_time_prepare result is a map, let's build a keyword list verbatim and only fetch necessary fields via the dot-notation access.
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
]
Changes
Plausible.Ingestion.WriteBuffercallsProcess.flag(:trap_exit, true)soterminate/2can flush the buffer on shutdown, buthandle_info/2only matched:tick. When a linked port or process (the ClickHouse connection socket) exits, the GenServer receives{:EXIT, port, :normal}and crashes with aFunctionClauseError, then restarts. This adds ahandle_info/2clause that ignores:EXITmessages so the buffer keeps running. Fixes #6382.