Skip to content

Bump nats-io from v3.9.2 to v3.14.0 - #119507

Open
actueleai wants to merge 16 commits into
ClickHouse:masterfrom
actueleai:bump-nats-io-v3.13.0
Open

actueleai wants to merge 16 commits into
ClickHouse:masterfrom
actueleai:bump-nats-io-v3.13.0

Conversation

@actueleai

@actueleai actueleai commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Bump nats-io from v3.9.2 to v3.14.0.

ClickHouse-side changes

  • src/Storages/NATS/NATSConnection.{h,cpp}, StorageNATS.cpp — the library now enables TLS by itself for tls:// addresses; an explicit nats_secure = 0 still disables it, and the setting docs say so.

Behaviour changes

  • A tls:// address in nats_url / nats_server_list now uses TLS without nats_secure = 1.

Fork

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Update nats-io from v3.9.2 to v3.14.0.


Workflow [PR]
Sync PR [sync-upstream/pr/119507]

Point `contrib/nats-io` at `ClickHouse/v3.13.0` (`137843892fbd`) of the
ClickHouse fork https://github.com/ClickHouse/nats.c, which is upstream
`v3.13.0` plus three build-portability patches (FreeBSD `sys/socket.h`,
`stdio.h` in `n-unix.h`, `natsp.h` included first in `js.c` and `kv.c`).

The previous fork patch "Remove legacy OpenSSL API usage" is dropped
because it became obsolete: upstream now requires OpenSSL 1.1.1+ and
removed the legacy init/cleanup calls and `TLSv1_2_client_method` usage
itself.

Notable upstream changes since v3.9.2 relevant to the NATS table engine:
* `natsConnection_Close` now always flushes properly.
* `nats_CloseAndWait` no longer segfaults on thread exit.
* JetStream async pull no longer double-frees a message.
* Fixed a deadlock in `js_MaybeFetchMore`.
* libuv event loop no longer crashes if the connection is destroyed
  while consuming; the socket is closed only after polling is done.
* `SSL_read`/`SSL_write` are protected with a mutex, and a possible
  hang during the TLS handshake was fixed.
* Connection drain no longer causes a missed reply or a 100ms delay.
* TLS is auto-enabled for the `tls://` URL scheme.
* New `ObjectStore` API (`src/object.c`), per-message TTL and pull
  consumer priority groups.

No changes were needed in `contrib/nats-io-cmake/CMakeLists.txt`: the
only new source file is `src/object.c`, which implements the standalone
`ObjectStore` public API and is not referenced by any translation unit
ClickHouse compiles, so it stays out of the source list just like the
`micro*.c` files already are.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thevar1able thevar1able added the can be tested Allows running workflows for external contributors label Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [59ddc78]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

⚠️ Review sessions stopped as a cybersecurity risk

The model provider stopped these review sessions as a possible cybersecurity risk:

  • attempt 1: gpt-6.1-sol

This summary comes from a session with gpt-5.4. A session is typically stopped when it reaches a memory-safety finding, and the finding is lost with it, so this review can miss a real defect. Please review the change in detail, and run the review internally with a model that has cyber access.

Summary

This PR bumps contrib/nats-io to the fork commit 523742ff and updates the ClickHouse-side NATS configuration so a tls:// address still honors an explicit nats_secure = 0. That ClickHouse-side fix looks correct, but I do not think the vendor pin is safe to merge yet: the submodule SHA still lives only on the temporary fork branch ClickHouse/v3.14.0-fixes, not on the long-lived ClickHouse/v3.14.0 branch.

PR Metadata
  • The selected Changelog category is not correct for a runtime dependency bump that changes NATS table behavior; this should be Improvement, not Build/Testing/Packaging Improvement.
  • The current Changelog entry is too internal and does not describe the user-visible effect. Suggested replacement:
    • Changelog category: Improvement
    • Changelog entry: NATS tables now enable TLS automatically for tls:// addresses unless nats_secure = 0 is set explicitly, and the bundled nats.c client is updated to v3.14.0 with ClickHouse compatibility fixes.
Findings
  • ❌ Blockers
    • [contrib/nats-io:1] The new submodule SHA 523742ff is still not reachable from the long-lived ClickHouse/nats.c branch origin/ClickHouse/v3.14.0: git branch -r --contains 523742ff shows only origin/ClickHouse/v3.14.0-fixes, and git merge-base --is-ancestor 523742ff origin/ClickHouse/v3.14.0 is false. That leaves this vendor pin as fragile as the earlier a988d8e1 pin: if the fixes branch is deleted or merged with rewritten SHAs, a fresh git submodule update --init for this ClickHouse revision can stop working, and the permanent fork branch still does not carry the ClickHouse-only fixes this PR depends on.
    • Suggested fix: merge the fork fixes onto ClickHouse/v3.14.0 without rewriting the commit the submodule points at (fast-forward or a merge commit that preserves reachability), then repin contrib/nats-io to the commit that actually lives on ClickHouse/v3.14.0.
Final Verdict

❌ Request changes

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. labels Sep 11, 2026
Comment thread contrib/nats-io Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 59ddc7819 with master cf7ef0be0 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

36 object files changed (+86.10 KiB total), 0 added.

Object file Master PR Δ
contrib/nats-io-cmake/CMakeFiles/_nats_io.dir/__/nats-io/src/js.c.o 107.39 KiB 124.34 KiB +16.95 KiB (+15.78%)
contrib/nats-io-cmake/CMakeFiles/_nats_io.dir/__/nats-io/src/jsm.c.o 146.45 KiB 162.55 KiB +16.10 KiB (+10.99%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

53 translation units recompiled, 59 s compile time in total, 53 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 A heads-up on ordering with #120202, which bumps the same submodule inside the current ClickHouse/v3.9.2 fork branch.

v3.13.0 is divergent from ClickHouse/v3.9.2 (merge base 233ca8ef) and does not carry three fixes that live only on the fork branch:

  • the EINTR retry in natsSock_WaitReady (src/unix/sock.c) — without it a poll interrupted by a signal is reported as a socket error, Cannot connect to Nats last error: (unix/sock.c:56): poll error: 4. v3.13.0 still has the bare poll() with the same message and no EINTR handling anywhere in its src/ tree. This is live: 65 CI failures across 56 distinct pull requests since 2026-09-14, and it is reachable outside CI too, since system.stack_trace signals every thread.
  • the libuv attach-ordering fix (ClickHouse/nats.c#5).
  • the JetStream fetch lock-order backport (ClickHouse/nats.c#6).

#120202 should land first, since it is the only open path for all three. Whichever of the two merges second has to carry the other's commits forward — so if this one lands after #120202, please port those three onto the v3.13.0 branch of the fork before bumping, otherwise the EINTR fix regresses and the NATS credentials-rotation tests start failing again.

Related: #120202
Related: #120201

actueleai and others added 2 commits October 1, 2026 14:49
Point `contrib/nats-io` at `ClickHouse/v3.13.0` (`6622c7dc92d0`) of the
ClickHouse fork https://github.com/ClickHouse/nats.c, which is upstream
`v3.13.0` plus five patches:

* build portability: `sys/socket.h` on FreeBSD and `stdio.h` in
  `src/include/n-unix.h`, and `natsp.h` included before `ctype.h` in
  `src/js.c` and `src/kv.c` (clang 15);
* libuv adapter: do not let an attach overtake a queued poll removal;
* libuv adapter: do not close an already released poll handle;
* retry `poll` on `EINTR` when waiting for a socket.

Two older fork patches are dropped because upstream absorbed them: the
legacy OpenSSL 1.1 API usage removal (upstream now requires OpenSSL
1.1.1+ and removed the legacy init/cleanup calls and
`TLSv1_2_client_method` itself) and the libc `rand` replacement
(v3.13.0 uses the `nats_Rand64` CMWC generator seeded from `RAND_bytes`).

Notable upstream changes since v3.9.2 relevant to the NATS table engine:

* TLS is auto-enabled for the `tls://` URL scheme, without an explicit
  `natsOptions_SetSecure` call.
* `natsConnection_Close` now always flushes properly.
* JetStream async pull no longer double-frees a message, and a deadlock
  in `js_MaybeFetchMore` was fixed.
* The libuv event loop no longer crashes if the connection is destroyed
  while consuming; the socket is closed only after polling is done.
* `SSL_read`/`SSL_write` are protected with a mutex, and a possible
  hang during the TLS handshake was fixed.
* Connection drain no longer causes a missed reply or a 100ms delay.
* New `ObjectStore` API (`src/object.c`), per-message TTL and pull
  consumer priority groups.

No changes were needed in `contrib/nats-io-cmake/CMakeLists.txt`: the
only new source file is `src/object.c`, which implements the standalone
`ObjectStore` public API and is not referenced by any translation unit
ClickHouse compiles, so it stays out of the source list just like the
`micro*.c` files already are. `src/version.h` is checked in, not
generated, and already carries 3.13.0.

Co-Authored-By: Claude Code <[email protected]>
@actueleai actueleai changed the title Bump nats-io from v3.9.2 to v3.13.0 Bump nats-io to v3.13.0 Oct 2, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Oct 2, 2026
alexey-milovidov and others added 3 commits October 9, 2026 01:10
Since upstream nats.c b89b44d0 (part of v3.13.0), `natsLibuv_Read`
calls `uv_poll_stop` from whichever thread removes the read event. On
`DROP TABLE`, `natsConnection_Close` runs in the query thread while the
`NATSHandler` loop thread is inside `uv_run`, so ThreadSanitizer reports
a data race between `uv__io_stop` and `uv__io_poll`, and the `DROP` hung.

Point `contrib/nats-io` at a fork commit that stops polling immediately
only from the event loop thread: ClickHouse/nats.c#14

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119507&sha=acb8e8bda856c88eda8525e5abbeec03074b0ce4&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%20targeted%29
PR: ClickHouse#119507

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sses

`nats-io` v3.13.0 enables TLS by itself for a `tls://` address in
`natsOptions_SetURL` / `natsOptions_SetServers`, unless the caller has
explicitly called `natsOptions_SetSecure`. `NATSConnection` only called it
for `nats_secure = 1`, so an explicit `nats_secure = 0` was lost. Carry the
`changed` flag of the setting into `NATSConfiguration` and call
`natsOptions_SetSecure(false)` when the setting is explicitly disabled.
Document the `tls://` behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The Integration tests (amd_tsan, targeted) failure (report) was caused by this bump. Upstream nats.c b89b44d0 makes natsLibuv_Read call uv_poll_stop from whichever thread removes the read event, so natsConnection_Close (from DROP TABLE) raced with uv_run in the NATSHandler loop thread (uv__io_stop vs uv__io_poll), and the DROP hung. CI history shows this race only on this PR.

The fix is in the fork, ClickHouse/nats.c#14: stop polling immediately only from the event loop thread. contrib/nats-io now points at that commit (903972d7, on branch ClickHouse/v3.13.0-libuv-read-loop-thread). Please merge the fork PR before this one, so the submodule commit lives on ClickHouse/v3.13.0.

I also addressed the review comment about explicit nats_secure = 0 with tls:// addresses, and merged master. Locally (release build) test_block_based_formats_2 and test_hiding_credentials pass.

Comment thread contrib/nats-io Resolved
middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Oct 12, 2026
`stacktraces_on_timeout_decorator` caught only `subprocess.TimeoutExpired`,
which is raised when the 600 s `DEFAULT_QUERY_TIMEOUT` wait expires. A
caller-supplied `timeout=` kills the client from a `Timer` instead, so
`get_answer`, `get_error` and `get_answer_and_error` raise
`QueryTimeoutExceedException`, and the `system.stack_trace` dump never ran
on that path.

Catch both exceptions. The dump now:
- runs at most once per (test, host, port), because caller timeouts sit in
  retry loops (`exec_query_with_retry`, `query_with_retry`) and a dump
  against a wedged server costs up to its 60 s bound;
- never raises: a failed dump is logged and the original exception
  propagates. Before, a dump that hit its own 60 s timeout replaced the
  original `TimeoutExpired` (PR ClickHouse#119507,
  test_storage_nats/test_nats_jet_stream.py::test_hiding_credentials);
- targets the host the request was sent to, like `query(host=...)` does;
- tags its rows with the test name (via `log_comment`) and logs where the
  dump went.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits October 17, 2026 19:28
…o` v3.13.0 fork

The bump dropped the ClickHouse-only `nats.c` fix 19edbc41 ("Destroy the
protocol parser on disconnect when an event loop is attached", backport of
nats-io/nats.c#1008) from the old `ClickHouse/v3.9.2` fork line. ClickHouse
drives `nats.c` through an external libuv event loop, so without it a half
decoded `MSG` payload could survive a reconnect and corrupt the next message.

The submodule now points to the cherry-pick of that commit on top of the
previously pinned 903972d7, pushed to the `ClickHouse/v3.13.0-parser-reset`
branch of https://github.com/ClickHouse/nats.c

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread contrib/nats-io Outdated
@@ -1 +1 @@
Subproject commit b88704dfeb55e0f1dee165b9c1daccb90d5816d4
Subproject commit a988d8e1d37a0c22a66314e762250e7b8a8f0643

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinning contrib/nats-io to a988d8e1 still does not put this bump on the long-lived ClickHouse/v3.13.0 fork line that the PR description says it follows. Right now that SHA is reachable only from the two open staging branches behind ClickHouse/nats.c PRs #14 and #15, not from ClickHouse/v3.13.0 itself.

That makes the vendor pin fragile: if those PRs are merged with rewritten SHAs or the staging branches are deleted, a fresh git submodule update --init for this ClickHouse revision can stop fetching contrib/nats-io, and the next bump also loses the permanent branch that should carry these ClickHouse-only patches. Please merge the fork PRs first and then repin contrib/nats-io to the commit that actually lives on ClickHouse/v3.13.0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Agreed, this must be settled before merging. Status as of 2026-10-29: ClickHouse/nats.c PRs #14 and #15 are still open. #15 is stacked on #14, and its head a988d8e1 is 2 commits ahead of and 0 behind ClickHouse/v3.13.0 (6622c7dc). If a maintainer merges both with a fast-forward (or with merge commits, which keep a988d8e1 reachable from ClickHouse/v3.13.0), the current pin stays valid and needs no repin. A squash or rebase merge would change the SHAs, and then contrib/nats-io would need a repin here. I am not merging the fork PRs myself, because that is a merge decision for a human. Please do not merge this PR until #14 and #15 have landed on ClickHouse/v3.13.0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Status as of 2026-11-24, since this thread still describes the earlier v3.13.0 pin. The PR now pins contrib/nats-io to 523742ff, which is the head of ClickHouse/nats.c#17 (ClickHouse/v3.14.0-fixes). That commit is 2 commits ahead of and 0 behind ClickHouse/v3.14.0 (5bd80ee8), so it is not yet reachable from the long-lived branch, and the concern here still holds.

What is needed is a human merge of ClickHouse/nats.c#17 into ClickHouse/v3.14.0 with a fast-forward or a merge commit. Either keeps 523742ff reachable, and then this pin needs no change. A squash or rebase merge would rewrite the SHA and require a repin here. I authored that fork PR, so I am not merging it myself. Its CI is red on every job, which needs a look before merging.

Please do not merge this PR until 523742ff is on ClickHouse/v3.14.0. I am leaving this thread unresolved for that reason. The branch is otherwise current: master is merged in as 8ae8f7e6 without conflicts, and src/Storages/NATS compiles against the pinned submodule.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status as of 2026-10-22: CI is green and the branch merges cleanly with master. The EINTR retry, the libuv attach-ordering fix and the poll-handle fix from #120202 are all on ClickHouse/v3.13.0 in the fork (merged there as ClickHouse/nats.c#12), so they are not lost by this bump.

The only remaining blocker is the one raised by the AI review: contrib/nats-io is pinned to a988d8e1, which is reachable only from the open fork PRs. ClickHouse/nats.c#15 is stacked on ClickHouse/nats.c#14 (a988d8e1's parent is 903972d7), so merging both into ClickHouse/v3.13.0 with merge commits (not squash or rebase) keeps a988d8e1 reachable from the long-lived branch, and no repin is needed here. That merge needs a maintainer of the fork. I am not merging it from automation.

Related: ClickHouse/nats.c#14
Related: ClickHouse/nats.c#15

alexey-milovidov and others added 3 commits October 29, 2026 20:55
Points `contrib/nats-io` at the `ClickHouse/v3.14.0` branch of the
`ClickHouse/nats.c` fork (head 5bd80ee87513), which rebases the ClickHouse
patch series onto upstream `v3.14.0`. `.gitmodules` already named the fork,
so its URL is unchanged.

Carried patches, all verified as still needed:
- `src/include/n-unix.h`: include `<stdio.h>` (FreeBSD).
- `src/js.c` and `src/kv.c`: include `natsp.h` before `ctype.h` for clang 15.
- The event-loop fixes: parser teardown on disconnect for an attached event
  loop (`src/natsp.h`, `src/conn.c`), the libuv adapter poll-handle fixes
  (`src/adapters/libuv.h`) and the `EINTR` retry in `natsSock_WaitReady`
  (`src/unix/sock.c`).

Patch dropped as obsolete: the `__FreeBSD__` arm of the `sys/socket.h` guard
in `src/include/n-unix.h`, because upstream now includes `<sys/socket.h>`
unconditionally. The two patches dropped in the previous bump (legacy OpenSSL
API removal, libc `rand` replacement) are still absent from upstream and are
not re-carried.

No ClickHouse-side adaptation was required:
`contrib/nats-io-cmake/CMakeLists.txt` still matches the v3.14.0 tree exactly
(no source file was added or removed; `src/object.c` and `src/micro*.c` stay
unused by `src/Storages/NATS`), `src/version.h` is checked in and now reports
3.14.0, and the public `nats.h` changes are purely additive.

Co-Authored-By: Claude Code <[email protected]>
@actueleai actueleai changed the title Bump nats-io to v3.13.0 Bump nats-io from v3.9.2 to v3.14.0 Oct 30, 2026
Comment thread contrib/nats-io Resolved
Comment thread contrib/nats-io Resolved
The new pin carries two fixes on top of `ClickHouse/v3.14.0`:
- The libuv adapter fix that stops polling immediately only from the
  event loop thread (`903972d7`), which the previous pin had dropped. It
  fixes the data race in `natsLibuv_Read` and the hanging `DROP TABLE`
  seen in the TSan integration tests:
  https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119507&sha=acb8e8bda856c88eda8525e5abbeec03074b0ce4&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%20targeted%29
- A fix for a double release of the connection reference when a
  subscription fails after `natsSub_create` assigned `sub->conn`.

Related: ClickHouse/nats.c#17

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. manual approve Manual approve required to run CI pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants