知其然,知其所以然
常见报错实测 2026-10-29

Node.js Error: listen EADDRINUSE:不同监听地址互相冲突的完整矩阵,127.0.0.1 与 :: 同端口时请求归谁,reusePort 在 macOS 上 ENOTSUP

实测 Node.js Error: listen EADDRINUSE: address already in use :::端口:err.code、errno -48 和 :::9701 怎么读,lsof 找占用进程;不同 host(::、0.0.0.0、127.0.0.1、::1、localhost)互相是否冲突的完整矩阵,以及 127.0.0.1 与 :: 同端口时请求被谁处理;reusePort 在 macOS 上是 ENOTSUP;父进程被杀后子进程仍占端口。

Node.js EADDRINUSE address already in use listen lsof 端口占用 报错 真实验证 动画演示
常见报错实测 2026-10-29

Node.js EMFILE: too many open files:ulimit -n 256 只能打开 245 个,console.log 自己也会崩,createReadStream 与 fs.watch 才会触发

实测 Node.js EMFILE: too many open files:ulimit -n 256 时只能打开 245 个(node 自己占 11 个),描述符用尽时 console.log 本身会崩溃;套接字同样占描述符;fs.promises.readFile 和 readFile 回调一次读 3000 个文件没有失败而 createReadStream 失败,限制并发 64 后全部成功;fs.watch 每个文件一个描述符。

Node.js EMFILE too many open files ulimit fs.watch createReadStream 报错 真实验证 动画演示
常见报错实测 2026-10-29

Node.js ERR_REQUIRE_ESM、Cannot use import statement outside a module:Node 26 上默认已不再报,什么情况下还会报

实测 Node 26 上 ERR_REQUIRE_ESM、Cannot use import statement outside a module 还剩什么:没有 package.json 时 import 直接能跑,type 没写时只有性能警告,type: commonjs 才报老错误;require(esm) 默认可用,含顶层 await 才报 ERR_REQUIRE_ASYNC_MODULE;具名导入 CJS、省略扩展名、目录 import、__dirname 等 ESM 报错的实际文字与修法。

Node.js ERR_REQUIRE_ESM Cannot use import statement outside a module require(esm) ERR_MODULE_NOT_FOUND ESM CommonJS 报错 真实验证 动画演示
常见报错实测 2026-10-29

Node.js FATAL ERROR: JavaScript heap out of memory:默认上限 4192 MB 怎么来,Buffer 为什么不触发,44 MB 的 JSON.parse 要占 92 MB

实测 Node.js FATAL ERROR: JavaScript heap out of memory:这台 16 GiB 的机器默认上限 4192 MB,--max-old-space-size 的报告值 = 设置值 + 96 MB;Node 26 的文字是 Ineffective mark-compacts near heap limit;上限翻倍能放的对象约翻倍;Buffer 300 MB 不触发而普通数组触发;44 MB 的 JSON.parse 后堆里 92 MB。

Node.js JavaScript heap out of memory max-old-space-size Ineffective mark-compacts JSON.parse Buffer 报错 真实验证 动画演示
常见报错实测 2026-10-29

Node.js TypeError: fetch failed:原因都在 e.cause 里,localhost 是 AggregateError,AbortSignal.timeout 是 TimeoutError

实测 Node.js TypeError: fetch failed:message 永远只有 fetch failed,真正的原因在 e.cause;localhost 的 cause 是 AggregateError,要读 .errors;ECONNRESET、UND_ERR_SOCKET、HTTPParserError、DEPTH_ZERO_SELF_SIGNED_CERT、ENOTFOUND、unknown scheme 各自的样子;AbortSignal.timeout 得到的是 TimeoutError;按 cause.code 决定是否重试。

Node.js TypeError: fetch failed ECONNREFUSED AggregateError AbortSignal.timeout cause UND_ERR_SOCKET 报错 真实验证 动画演示
常见报错实测 2026-10-29

Nginx 502 Bad Gateway:error.log 里 connect() failed、prematurely closed、sent too big header 各是什么故障,上游全挂后恢复要等 fail_timeout

实测 Nginx 502 Bad Gateway:error.log 里 connect() failed (61: Connection refused)、upstream prematurely closed connection、Connection reset by peer、upstream sent too big header 各对应什么上游故障;上游自己返回的 502 与 nginx 生成的 502 怎么区分;proxy_buffer_size 与 error_page 的效果;两台上游都挂后,恢复也要等 fail_timeout(2.5 s 才首次成功)。

Nginx 502 Bad Gateway connect() failed upstream prematurely closed connection no live upstreams proxy_pass 报错 真实验证 动画演示
常见报错实测 2026-10-29

Nginx 504 Gateway Time-out:proxy_read_timeout 是读间隔不是总时长,GET 超时会换上游重试而 POST 不会,默认 60 s 实测

实测 Nginx 504 Gateway Time-out:error.log 的 upstream timed out (60: Operation timed out) while reading response header from upstream;proxy_read_timeout 是两次读之间的间隔不是总时长(4 s 的涓流响应 1 s 超时也完整返回);响应体中途停住时客户端看到的不是 504;GET 超时会被换到下一台上游重试而 POST 不会;默认值实测 60.0 s。

Nginx 504 Gateway Time-out upstream timed out proxy_read_timeout proxy_next_upstream 报错 真实验证 动画演示
常见报错实测 2026-10-29

Nginx 413 Request Entity Too Large:默认 1 MiB 的边界精确到 1 字节,client_max_body_size 写在哪个 location 才生效

实测 Nginx 413 Request Entity Too Large:默认限制 1 MiB,1048576 字节通过、1048577 字节 413;client_max_body_size 放在哪个 location 才生效;0 表示不检查;有 Content-Length 时读完请求头就拒绝、分块传输要读到超过才拒绝;error_page 把 413 换成 JSON;上游自己返回的 413 怎么分辨。

Nginx 413 Request Entity Too Large client_max_body_size client intended to send too large body error_page 报错 真实验证 动画演示
常见报错实测 2026-10-29

Nginx [emerg] 启动失败:15 个常见配置错误的 nginx -t 原文,nginx -t 通过仍会 bind() failed,reload 失败时旧配置继续生效

实测 Nginx [emerg] 启动失败:15 个错误配置在 nginx -t 里各是什么报错(unknown directive、is not terminated by ";"、unexpected "}"、host not found in upstream 等)、哪些不会失败(include 通配符没匹配到文件、重复 server_name 只是 warn);nginx -t 通过仍可能 bind() failed (48: Address already in use);reload 失败时旧配置继续生效;proxy_pass 用变量推迟到运行时 502。

Nginx [emerg] unknown directive bind() failed Address already in use host not found in upstream nginx -t reload 报错 真实验证 动画演示
常见报错实测 2026-10-29

Nginx 404 与 403:root 和 alias 的路径拼接、目录请求为什么是 403、SPA 的 try_files 让缺失资源返回 200

实测 Nginx 404 与 403:root 把整个 URI 接在后面、alias 替换匹配部分,结尾斜杠不一致会拼成 filesa.txt 或让 /staticx.txt 也匹配;目录没有 index 是 403 而不是 404;文件和上级目录的权限引起的 403;SPA 的 try_files 回退会让缺失的静态资源返回 200 的 HTML。

Nginx 404 Not Found 403 Forbidden root alias try_files autoindex directory index forbidden 报错 真实验证 动画演示
常见报错实测 2026-10-29

PostgreSQL FATAL: sorry, too many clients already:普通用户最多占 7/10,第 8 个先报 remaining connection slots,调大要重启

实测 PostgreSQL FATAL: sorry, too many clients already:max_connections = 10 时普通用户最多占 7 个,第 8 个先报 remaining connection slots are reserved for roles with the SUPERUSER attribute,全满才报 too many clients;pg_stat_activity 找占用者;调大 max_connections 要重启(pending_restart);角色与数据库的连接限制是另外的报错;idle_session_timeout 回收闲置连接。

PostgreSQL sorry too many clients already max_connections superuser_reserved_connections pg_stat_activity idle_session_timeout 报错 真实验证 动画演示
常见报错实测 2026-10-29

PostgreSQL ERROR: deadlock detected:先开始等锁的会话被回滚,服务端日志才有两边的语句,统一加锁顺序后死锁从 19/20 降到 0

实测 PostgreSQL ERROR: deadlock detected:两个会话反序更新两行,先开始等锁的被回滚(6 次都是 A,换启动顺序则是 B);检测耗时约等于 deadlock_timeout(0.63 / 1.53 / 3.53 s);服务端日志才有两边的完整语句;统一加锁顺序让 20 个并发事务的死锁从 19 个降到 0,但总用时从 2.3 s 变成 6.1 s;SQLSTATE 是 40P01。

PostgreSQL deadlock detected 40P01 deadlock_timeout log_lock_waits 死锁 报错 真实验证 动画演示
京ICP备2026067502号-1京公网安备11010502063487号