Repository navigation
Conversation
|
LGTM. This fixes the hang in #8021: when the pipeline stops, the endpoint no longer waits on a Postgres worker stuck in a call that never returns. What I ran (debug build, no local Postgres)
Gates: tests, docs and changelog are present. The commit message is good. There is no Missing (medium): no unit test, without Postgres, for the shutdown path of + #[test]
+ fn broadcast_gives_up_on_shutdown_with_a_silent_worker() {
+ use super::super::{BroadcastCommand, WorkerHandle, WorkerResult};
+ use std::time::{Duration, Instant};
+ use tokio_util::sync::CancellationToken;
+ let (release, blocked) = crossbeam::channel::bounded::<()>(0);
+ let (cmd_tx, cmd_rx) = crossbeam::channel::bounded(1);
+ let (result_tx, result_rx) = crossbeam::channel::bounded(1);
+ let thread = std::thread::spawn(move || {
+ let _cmd = cmd_rx.recv();
+ let _ = blocked.recv();
+ let _ = result_tx.send(WorkerResult::Ok { num_bytes: 1, num_rows: 1 });
+ });
+ let token = CancellationToken::new();
+ let mut endpoint = PostgresOutputEndpoint { /* as in drop_returns_with_a_blocked_worker */
+ shutdown_token: Some(token.clone()), /* ... */ };
+ token.cancel(); // (or cancel from another thread after the wait starts)
+ assert!(endpoint.broadcast_and_collect(BroadcastCommand::BatchEnd).is_err());
+ // The late reply must not be taken by the next command.
+ drop(release);
+ assert!(endpoint.broadcast_and_collect(BroadcastCommand::BatchStart).is_err());
+ assert_eq!(endpoint.num_rows, 0);
+ }Other uncovered cases (low): a |
|
Thanks. Added a variant of your test in 36cec7f: |
A pipeline could fail to stop when the Postgres output connector waited for a server or a connection pooler that accepted the TCP connection and then did not answer. The worker thread stayed in a synchronous call of the postgres client, which has no way to end the call from another thread. The endpoint waited for the reply of the worker with no limit, on the output thread of the controller, which the teardown joins. The drop of the endpoint also joined each worker with no limit. The endpoint now keeps the shutdown token of the pipeline. Each send to a worker and each wait for a reply looks at the token every 100 ms and gives up when the pipeline stops. A later wait checks the token first, so it cannot take a late reply for a new command. An abandoned wait is not reported as an error of the connector. The drop of the endpoint sends Shutdown without a wait, gives all the workers one second together to end, joins the ones that ended, and leaves the others with a warning. Such a thread is in a call to PostgreSQL, and ends with the process. Not changed: there is still no time limit for the calls themselves, and the connect and prepare when the pipeline starts. Two suite cases use a new proxy fault that takes a statement, or a login after a lost session, and gives no answer. Each checks that the pipeline then stops within 20 seconds. A unit test checks that the drop returns with a worker that does not end. All three fail without the fix. Fixes: #8021 Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
A unit test with a worker that takes a command and does not answer: when the pipeline stops during the wait, the wait ends with an error, and the next wait does not take the late reply of the worker. The test needs no PostgreSQL server. It fails without the shutdown check. Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
A worker that was left behind in a call to PostgreSQL could go on when the server answered later, and commit its batch after the stop had returned. The worker now checks whether its pipeline stopped before each statement and before COMMIT, and rolls back instead. A COMMIT that was already sent can still complete. A worker built with no controller, as in tests, never counts as stopped for this check; one whose controller is gone does. The docs and the changelog now say that a graceful stop of a pipeline with checkpoints first makes a checkpoint, which waits for the output of the connector, so it can stay in Suspending while the server does not answer, and that /stop?force=true does not wait. Tests: - The unit test of the silent worker cancels only after the endpoint has waited in its receive loop, and checks that a cancelled wait leaves the late reply in the channel. - The test proxy no longer lets a server timeout release a held client: for a held login it opens no server connection, and for a held statement the relay from the server stops while the fault holds the session. The two stop cases still fail without the fix. Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
| - Connectors: a pipeline with a PostgreSQL output connector now stops when | ||
| the server or a connection pooler does not answer. Before, the stop could | ||
| wait with no time limit. | ||
|
|
||
| - Connectors: the stop of a pipeline with a PostgreSQL output connector no | ||
| longer waits for a server or a connection pooler that does not answer. | ||
| Before, the stop could wait with no time limit. A graceful stop of a | ||
| pipeline with checkpoints first makes a checkpoint, which waits for the | ||
| output of the connector, so it can stay in `Suspending`; use | ||
| `/stop?force=true` in that case. A writer thread that sees the stop | ||
| before it sends `COMMIT` rolls back its part of the batch. | ||
|
|
There was a problem hiding this comment.
bug (medium): These are two entries for the same fix. The first one, from commit 1, repeats the opening of the second. Keep only the second entry.
There was a problem hiding this comment.
Fixed in 3a61218: the first entry is removed. It was a duplicate from a rebase.
| } | ||
|
|
||
| // A stop cannot cancel a COMMIT that the worker has already sent. | ||
| if self.controller_requested_shutdown() { |
There was a problem hiding this comment.
missing test (medium): No test covers the roll-back-instead-of-COMMIT path (or the skip in exec_statement at L300). Both stop cases end the proxy session on release, so the worker never gets as far as COMMIT. Suggested suite case: add a fault that holds a B and then forwards it on release. Then hold, call controller.stop(), release, give the worker time to finish, and assert the target table has none of the batch's rows. Without that test, nothing would notice if the check were removed and a late COMMIT landed after the stop.
There was a problem hiding this comment.
Added in 3a61218: rolls_back_a_batch_after_stop. A new proxy fault holds a Bind and forwards it on release. The case stops the pipeline, releases, waits for the session to end, and checks that the table is empty and that the sequence of the table advanced once. Without the check before COMMIT the table has 1 row. Without the skip in exec_statement the sequence is at 2.
|
What I ran
Review
With those two fixed, this looks good to merge. |
No test reached the check before COMMIT, or the skip of a statement after the pipeline stopped: both stop cases ended the proxy session, so the worker never got that far. The new suite case holds a statement in the proxy, stops the pipeline, and then lets the statement through. The table must have no row of the batch, and the sequence of the table must show that no later statement reached the server. Each of the two checks, when removed, fails the case. The drop of the endpoint gave up on its workers after one second also for an endpoint with no controller, so a test or a benchmark could leave a worker thread with an open connection. Apply the limit only when the endpoint has the shutdown token of a pipeline. Remove a duplicate changelog entry that a rebase left. Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
|
Status of the review points, as of 3a61218:
|
swanandx
left a comment
There was a problem hiding this comment.
A question before I review the details: when does this hang happen in production? On stop, the manager kills the pipeline process. A graceful stop with a checkpoint still hangs with this PR, as the new docs say. If the fix is for in-process stops only, please say so in the description.
Also, changelog.md has two entries for this fix. Please keep one.
Linked Issue
Fixes #8021. Found during the review of #8017 (related to #8014).
What changes
A pipeline could fail to stop when the Postgres output connector waited for a server or a pooler that accepted the TCP connection and did not answer. The synchronous
postgresclient cannot end a call from another thread, so the worker can stay in its call. This PR makes sure that nothing on the output thread waits for such a worker when the pipeline stops, as the rule onOutputEndpointrequires.batch_start,encode,batch_end)recv(), no limitsend(), no limitDropof the endpointShutdownwithout a wait, gives all workers 1 s together, joins the ones that ended, leaves the others with a warning (they end with the process)An endpoint with no controller (tests, benchmarks) waits as before.
Not changed (out of scope):
connect_timeout, statement timeout).PostgresOutputEndpoint::new, which run when the pipeline starts, not on the output thread.Describe Manual Test Plan
stops_with_an_unanswered_statement: the proxy takes a statement of a transaction and gives no answer; the pipeline is stoppedstops_with_an_unanswered_login: the proxy ends the session, then takes the next login and gives no answerdrop_returns_with_a_blocked_workerthe pipeline did not stop within 20 secondsthe endpoint did not drop within 5 secondsThis PR touches the same functions as #8020, #8027, #8096 and #8098. The ones that merge later need a rebase. #8096 changes the protocol between the endpoint and its workers; after it, the waits of this PR are only in
batch_end.Checklist
Breaking Changes?
None.