使用"database.host": "localhost" 时连接很慢

Open Beginner friendly
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
databases

Research direction

Read questdb_database.py, especially the conninfo construction and the default self.host value. Reproduce the localhost and 127.0.0.1 connection cases on Windows, then verify that instantiating QuestdbDatabase with database.host=localhost no longer incurs the reported delay.

Written by the indexing model from the issue text.

Description

┌─────────────────────────┬───────────────────────────┐
│ 测试 │ 耗时 │
├─────────────────────────┼───────────────────────────┤
│ ::1:8812 (IPv6) │ 立即拒绝 (WinError 10061) │
├─────────────────────────┼───────────────────────────┤
│ 127.0.0.1:8812 (IPv4) │ 0.000s ✅ │
├─────────────────────────┼───────────────────────────┤
│ host=127.0.0.1 直连 │ 0.000s ✅ │
├─────────────────────────┼───────────────────────────┤
│ host=localhost (第二次) │ 130.079s ❌ │
└─────────────────────────┴───────────────────────────┘

完整根因报告

问题

vnpy 调用 vnpy_questdb 启动慢(每次实例化 QuestdbDatabase 都额外卡 130 秒)。

根因

questdb_database.py 中 conninfo 拼接用的是 host=localhost:

self.conninfo: str = (
f"host={self.host} " # ← self.host 默认 "localhost"
f"port={self.port} "
...
)

在 Windows 上 localhost 解析为 ::1 (IPv6) 和 127.0.0.1 (IPv4)。QuestDB 默认只监听 IPv4(netstat 显示
0.0.0.0:8812),不接受 IPv6。

libpq 解析 localhost 后串行尝试每个地址,每个地址用尽默认 connect_timeout(~120 秒)后才尝试下一个。所以:

  1. 试 ::1 → 立即被 OS 拒绝 → libpq 不认为这是"快速失败",继续重试直到 ~120s 超时
  2. 才轮 127.0.0.1 → 成功 → 总耗时 ~130s

验证结果

Dominant language
Python
Stars
3
Forks
6
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vnpy/vnpy_questdb

All issues in vnpy/vnpy_questdb

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.