a playground on an ephemeral port another process holds on loopback should not leave its clients hanging

未关闭
#6,476 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
clojure, java, postgresql

调研方向

Start with test-resolves-other-db in the multi-db test namespace (multi_db_test.clj, around line 22), where the pgjdbc connection is built, and with the Playground's connection builder, which turns a wildcard bind into localhost. Reproducing needs a macOS machine with another process holding the same port on loopback. Done means the test fails within a bounded timeout instead of hanging, and the bind behaviour for ephemeral ports is decided, since the issue lists several approaches without choosing one.

由索引模型根据 Issue 内容生成。

描述

pgwire unshaved-yak

A full ./gradlew test run on macOS hung for over an hour in xtdb.sql.multi-db-test/test-resolves-other-db. The test's pgjdbc connection to the playground connected, then waited forever for a reply that never came, because it had reached a different process.

Symptoms

  • The suite's hang watchdog reported no test activity for 257s (last event: started: test-resolves-other-db) and dumped threads, but the run then sat idle until killed.
  • The Test worker thread was parked in org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication (reading the server's first reply) under xtdb.api.DataSource$ConnectionBuilder.build at multi_db_test.clj:22.
  • On the server side both pgwire accept loops were parked in accept, and no connection handler existed for that client.

Root cause

The playground had come up on 0.0.0.0:49152, the first ephemeral port, straight after the previous server took 65534 and 65535. netstat -Lan showed two listeners on that port:

0/0/50    *.49152            the playground (wildcard)
0/0/128   127.0.0.1.49152    another process, bound to loopback specifically
  • The bind succeeds on macOS. Java's ServerSocket sets SO_REUSEADDR, and BSD lets a wildcard bind share a port with an existing address-specific one.
  • The client reaches the other process. Playground's connection builder turns a wildcard bind into localhost, and the kernel routes 127.0.0.1:49152 to the more specific loopback binding.
  • Nothing times the client out. The test's connection sets no socketTimeout or loginTimeout, so pgjdbc waits forever for the other process to speak Postgres.

Assumptions

  • assumption: the other listener was Tailscale's system extension. lsof without root couldn't see its owner, but Tailscale held an established connection to 127.0.0.1:49152 at the same time.
  • assumption: Linux refuses the wildcard bind while the specific one is listening, so this is macOS-only, and CI on Linux won't see it.
  • assumption: a node bound with :port 0 in any test has the same exposure; the playground just happened to land on the contested port.

Potential approaches

  • The server could bind with setReuseAddress false when asked for an ephemeral port, so the kernel never hands out a port that is already held on a specific address.
  • Test connections could carry a socketTimeout, so a wrong peer fails the test instead of hanging the suite.
  • The hang watchdog could fail the run once it has reported, rather than leaving it idle.
主要语言
Clojure
星标
3.1k
派生
193
平均合并
1 天 8 小时
30 天内合并 PR
73

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

xtdb/xtdb 的其他 Issue

查看 xtdb/xtdb 的全部 Issue

相似的 Issue

更多 Clojure Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。