db_connect appends ?connect_timeout=3 to a keyword-form DATABASE_URL, which changes the database's name

未关闭 适合新手
#2,355 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, postgresql

调研方向

后缀是在 src/ext_db.c 的 db_connect 路径中追加的,该路径读取 DATABASE_URL。先使用 DATABASE_URL='host=/tmp/sock dbname=app' 复现问题,并在服务器日志中查看被破坏的数据库名称。然后在两种方案中选择:对关键字字符串添加 connect_timeout=3,或者以清晰的错误信息拒绝非 URI 输入。更新 docs/BUILTINS.md 中的数据库章节,并添加一个同时覆盖两种形式的测试。当关键字形式的 URL 能够连接,或以明确的信息失败,并且数据库名称从不被修改时,即为完成。

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

描述

area:stdlib kind:bug

Found by a consumer's test harness at 54008422 (make server-db), which first gave DATABASE_URL in libpq's keyword form.

What happens

db_connect of null reads DATABASE_URL and appends a timeout to it before connecting (src/ext_db.c): &connect_timeout=3 when the text holds a ?, and ?connect_timeout=3 otherwise. That is right for a URI (postgresql://...). libpq also accepts a keyword string (host=/path dbname=app), and for that form the suffix becomes part of the last value.

Reproduce

With DATABASE_URL='host=/tmp/sock dbname=app':

print of (db_connect of null)

PostgreSQL's log then shows FATAL: database "app?connect_timeout=3" does not exist. The program sees only a failed connection.

Done when

  • A keyword-form DATABASE_URL connects (the timeout is added as connect_timeout=3), or db_connect refuses a DATABASE_URL that is not a URI with an error that says so. It no longer changes the database's name.
  • docs/BUILTINS.md, in the database extension's section, says which forms DATABASE_URL takes.
  • A test covers both forms.
主要语言
C
星标
3
派生
7
平均合并
3 小时 30 分钟
30 天内合并 PR
264

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

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

InauguralSystems/EigenScript 的其他 Issue

查看 InauguralSystems/EigenScript 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

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