Skip to content

fix(connections): drain password-source command output without a reader race#1841

Merged
datlechin merged 1 commit into
mainfrom
fix/password-source-pipe-drain
Jul 9, 2026
Merged

fix(connections): drain password-source command output without a reader race#1841
datlechin merged 1 commit into
mainfrom
fix/password-source-pipe-drain

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

Splits the PasswordSourceResolver change out of #1813 (a MongoDB numeric-literal fix), where it was bundled without a description, test, or CHANGELOG entry.

resolveCommand runs a shell command to fetch a connection password (used by command, 1Password, Vault, and AWS Secrets Manager sources) and reads its stdout/stderr. The old code drained the pipes with readabilityHandler, then set the handlers to nil and called readDataToEndOfFile() after the process exited. Setting a readabilityHandler to nil does not wait for an in-flight handler block, so a handler could append a chunk after readDataToEndOfFile() had already appended the tail. The collector is lock-guarded, so bytes are not corrupted individually, but they can land out of order, which garbles the resolved password.

Change

  • Drain stdout and stderr with one blocking read loop per stream on a concurrent DispatchQueue, joined with a DispatchGroup. Each stream has a single reader, so appends stay in order, and the two streams drain in parallel so neither can block the other by filling its pipe buffer.
  • Behavior is otherwise unchanged: the 1 MB output cap still throws outputTooLarge (and terminates the process), the 30s timeout still throws commandTimedOut, and a non-zero exit still throws commandFailed with stderr.

Tests

New PasswordSourceResolverTests:

  • stdout is returned trimmed
  • a large stdout (300 KB) drains in full and in order while stderr is also draining
  • a failing command surfaces its exit code and stderr
  • output over the 1 MB cap fails as outputTooLarge
  • a command past the timeout is terminated and fails as commandTimedOut
  • empty output fails as emptyPassword

Notes

@datlechin datlechin force-pushed the fix/password-source-pipe-drain branch from 86d7dcf to ae5a2ab Compare July 9, 2026 06:19
@datlechin datlechin merged commit fe7f477 into main Jul 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86d7dcfc42

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@testable import TablePro

@Suite("PasswordSourceResolver command output")
struct PasswordSourceResolverTests {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Rename duplicate test suite type

Because TableProTests is a file-system-synchronized target in TablePro.xcodeproj/project.pbxproj, this new file is compiled into the same test module as TableProTests/Core/Utilities/PasswordSourceResolverTests.swift, which already declares struct PasswordSourceResolverTests at line 11. Building the test target will therefore hit an invalid redeclaration; rename this suite or merge these tests into the existing suite.

Useful? React with 👍 / 👎.

datlechin added a commit to andiahmads/TablePro that referenced this pull request Jul 9, 2026
datlechin added a commit that referenced this pull request Jul 9, 2026
* fix(plugin-mongodb): emit only JSON-valid numeric literals

* refactor(plugin-mongodb): share JSON-number check and quote Int64-overflow integers

* fix: drain password command pipes deterministically

* fix(plugin-mongodb): quote non-finite numbers and keep decimal _id filters exact (#1813)

* revert(connections): move password pipe-drain change to its own PR (#1841)

* docs(changelog): put the MongoDB fix under Unreleased and note the plugin update

---------

Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Ngo Quoc Dat <datlechin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant