编程技巧 - 文章列表
-
Node.js升级到17以后构建报error:0308010C:digital envelope routines::unsupported的解决方法(webpack的MD4、NODE_OPTIONS与hashFunction定位)
把Node.js升到17以上后跑npm run build报错error:0308010C:digital envelope routines::unsupported,堆栈落在webpack的createHash.js,根因是OpenSSL 3把MD4移进legacy provider、webpack 4默认拿它算模块hash。先用node -p复现,再选NODE_OPTIONS=--openssl-legacy-provider临时绕过、output.hashFunction改xxhash64、或升级webpack到5.61.0,附各平台写法。
-
MySQL报ERROR 2006 (HY000): MySQL server has gone away的排查方法(wait_timeout、max_allowed_packet与连接保活定位)
跑批脚本执行到一半报ERROR 2006 (HY000): MySQL server has gone away,重跑又正常,根因是连接已被服务端或中间网关单方面关掉。先用mysqladmin version与Aborted_clients排除mysqld重启,再核wait_timeout、interactive_timeout、net_write_timeout、max_allowed_packet四个参数;大包超限要服务端与客户端两头一起调,空闲被NAT掐断则靠连接池保活与mysql_ping探测重建,附完整命令与my.cnf配置。
-
Spring WebFlux报Could not emit tick 257 due to lack of requests与OverflowException的排查方法(onBackpressureDrop、limitRate与flatMap并发数定位)
Spring WebFlux里用Flux.interval定时跑批报OverflowException: Could not emit tick 257 due to lack of requests,根因是interval为热数据源按节拍发、不看下游request(n),flatMap默认并发256补货追不上就由failWithOverflow打断流。用onBackpressureDrop丢溢出tick、改concatMap冷源串行、或onBackpressureBuffer与limitRate控节奏;StepVerifier的thenRequest可稳定复现。
-
Kubernetes里PVC一直Pending的排查方法(kubectl describe pvc看Events、StorageClass与WaitForFirstConsumer定位)
kubectl get pvc看到PVC停在Pending、Pod报pod has unbound immediate PersistentVolumeClaims,先跑kubectl describe pvc读Events,区分WaitForFirstConsumer、FailedBinding、ExternalProvisioning;再核静态PV的容量、accessModes、storageClassName,或查CSI驱动与csi-provisioner日志。命名空间配额、ReadWriteOnce跨节点、Retain卷claimRef未清也会卡住绑定。
-
Python报json.decoder.JSONDecodeError: Expecting value的排查方法(空响应体、BOM与python -m json.tool定位)
json.loads()解析接口返回报JSONDecodeError: Expecting value: line 1 column 1 (char 0),第一反应常是JSON格式写错了,实际多半是传进去的根本不是JSON。空字符串、网关返回的HTML错误页、单引号、尾逗号、UTF-8 BOM都会撞这一句。先看repr(resp.text)与status_code,再用python -m json.tool验;Python 3.5起异常带pos、lineno、colno、doc四个属性能精确定位。数据核对到2026年11月。
-
Java报ConcurrentModificationException的排查方法(for-each遍历删除、modCount与Iterator.remove、removeIf定位)
Java遍历List删元素报ConcurrentModificationException,多数不是多线程问题,是for-each背后那个Iterator发现modCount变了。集合都是fail-fast,next()里比对expectedModCount。删倒数第二个元素反而不抛、静默跳过一个,最坑。用Iterator.remove()、removeIf、倒序for、先收集再removeAll四种写法都能绕开;真多线程才轮到CopyOnWriteArrayList与ConcurrentHashMap。2026年11月核对。
-
g++链接报undefined reference to的排查方法(静态库顺序、--start-group与nm -C、c++filt定位符号)
g++链接报undefined reference to,多半是静态库顺序摆反了。GNU ld单遍从左到右扫描,被依赖的库要排在后面;先用nm -C与c++filt确认符号在库里、排除extern C的命名差异,再用-Wl,--start-group与-Wl,--end-group验证顺序问题,make VERBOSE=1看真实命令行,CMake里用PUBLIC、PRIVATE写清传递性。数据核对到2026年11月。
-
Node.js报listen EADDRINUSE: address already in use的排查方法(端口占用、TIME_WAIT与server.close重启定位)
Node.js启动服务报listen EADDRINUSE: address already in use,是端口被别的进程占着,跟代码无关。用lsof -i :3000或ss -ltnp揪出占用PID,区分旧进程没退、nodemon重启竞态、cluster重复listen、Docker已发布端口、CI并行worker五种成因。Node默认已设SO_REUSEADDR,TIME_WAIT一般不用调,别再照抄tcp_tw_recycle。热重载放进server.close回调,测试用listen(0)让系统分端口。数据核对到2026年11月。
-
PHP报Maximum execution time of 30 seconds exceeded的排查方法(max_execution_time、set_time_limit与php-fpm超时分层定位)
PHP报Maximum execution time of 30 seconds exceeded,来自max_execution_time默认30秒。Linux上只算脚本自身执行时间,慢SQL与sleep不计入,Windows按墙钟算;PHP 8.3.0起ZTS改用per-thread timer。这句try/catch拦不住,用register_shutdown_function留现场。限墙钟要逐层设fastcgi_read_timeout、request_terminate_timeout与CURLOPT_TIMEOUT。
-
Go报fatal error: all goroutines are asleep - deadlock!的排查方法(channel收发、sync.WaitGroup与sync.Mutex循环等待定位)
Go程序报fatal error: all goroutines are asleep - deadlock!,是runtime的checkdead()发现运行中的M归零、timer堆也空,判定全局死锁。五种成因:无缓冲channel只发不收、nil channel阻塞、sync.WaitGroup计数不匹配、sync.Mutex持锁等channel、多把锁顺序不一致。局部卡死不报错,挂net/http/pprof抓goroutine与block profile,GOTRACEBACK=all打全栈。数据核对到2026年11月。