Estacyl opened a new pull request, #13457:
URL: https://github.com/apache/seatunnel/pull/13457
Yes, I am contributing this fix to Apache SeaTunnel.
### Purpose of this pull request
Fixes #13452.
I fixed two reconnect-handling issues in `WebSocketSourceClient` when
`open_messages` sends are rejected:
1. **Enforce `max_reconnect_times` across consecutive failed open-message
sends:** `SourceWebSocketListener.onOpen()` previously reset `reconnectTimes`
to `0` before sending `open_messages`. When each handshake succeeded and
`webSocket.send()` rejected an open message, canceling the socket triggered
`onDisconnected()` with the reset counter, allowing retries to continue
indefinitely at attempt `1/N`. I moved the recovery state reset
(`reconnectTimes`, `fatalError`, and `connectedTimestamp`) to run only after
all configured `open_messages` are sent.
2. **Prevent stale open-message send errors from masking later pre-handshake
failures:** `openMessageSendFailure` was previously stored on
`WebSocketSourceClient` and cleared only in `onOpen()`. If an earlier
connection rejected an open message and the final attempt failed before
`onOpen()`, `asTerminalError()` still reported the earlier send failure as the
terminal error message. I scoped `openMessageSendFailure` to each
`SourceWebSocketListener` instance (one per connection attempt) and consume it
on disconnect, passing it explicitly into `onDisconnected()` and
`asTerminalError()`.
### Does this PR introduce _any_ user-facing change?
Yes, bug fix compared to `dev` (unreleased after #12716):
- Consecutive open-message send rejections now count toward
`max_reconnect_times` and fail the task with `SEND_MESSAGE_FAILED` once the
retry budget is exhausted.
- If an earlier attempt rejected an open message and the final reconnect
attempt fails before the handshake completes, the task now fails with
`CONNECT_FAILED` naming the exhausted reconnect attempts and keeping the final
connection error as its cause instead of reporting the earlier send failure.
### How was this patch tested?
I extended `WebSocketSourceClientFatalErrorTest` with three deterministic
stub-socket unit tests covering:
- `shouldExhaustReconnectBudgetWhenOpenMessageSendKeepsFailing`: verifies
consecutive open-message send failures exhaust `max_reconnect_times` and
surface `SEND_MESSAGE_FAILED` with the final cause.
- `shouldReportConnectionFailureWhenFinalAttemptFailsBeforeOnOpen`: verifies
that after an earlier open-message rejection, a final attempt failing before
`onOpen()` surfaces `CONNECT_FAILED` with the final handshake error as cause.
- `shouldResetReconnectBudgetAfterOpenMessagesSucceed`: verifies that a
reconnect that successfully sends all open messages resets the reconnect budget
for subsequent drops.
Before applying the fix, I verified that the first two new tests failed for
the reported causes (`expected: <2> but was: <3>` scheduled reconnects, and
`expected: <CONNECT_FAILED> but was: <SEND_MESSAGE_FAILED>`).
After applying the fix, I ran:
- `JAVA_HOME=/usr/lib/jvm/java-17-openjdk ./mvnw -pl
seatunnel-connectors-v2/connector-websocket spotless:apply spotless:check
verify -B -o` — all 42 unit tests in `connector-websocket` passed, Spotless
passed, and packaging verified.
- `python3 tools/check_connector_registration.py` — passed (130 connector
modules checked).
Note: Testcontainers E2E (`connector-websocket-e2e`) was not run locally
because reproducing deterministic `WebSocket.send()` rejections requires
stub-socket callback control rather than a live server.
### Check list
* [x] If any new Jar binary package adding in your PR, please add License
Notice according
[New License
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
(no new jar)
* [x] If necessary, please update the documentation to describe the new
feature. https://github.com/apache/seatunnel/tree/dev/docs (existing docs
already describe the expected reconnect limit behavior)
* [x] If necessary, please update `incompatible-changes.md` to describe the
incompatibility caused by this PR. (not needed, bug fix on `dev`)
* [x] If you are contributing the connector code, please check that the
following files are updated: (not a new connector; existing registration and
E2E files do not require updates)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]