记一次openrestry问题

背景

团队所做的微服务,统一签名校验是在openrestry(nginx)的lua脚本计算的
突然有人报告了一个bug,当post请求body大于10k的时候,签名就会失效

原因

在读取body参数时候,使用ngx.req.get_body_data

This function returns nil if

1. the request body has not been read,  
2. the request body has been read into disk temporary files,  
3. or the request body has zero size.  

很明显是命中了第二条,body太大,会被存储到临时文件,此时需要使用ngx.req.get_body_file读取body

解决

按照文档里面说的,强制使用内存读取body
To force in-memory request bodies, try setting client_body_buffer_size to the same size value in client_max_body_size.