buguge - Keep it simple,stupid

知识就是力量,但更重要的,是运用知识的能力why buguge?

导航

未对参数做非空校验,我的服务被搞得内存溢出(OOM/OutOfMemoryError)了!

优付公众号上的自由职业者签约——用户关注我司公众号,访问公众号里的自由职业者签约H5,在这个H5页面上完成自由职业者签约。

程序实现逻辑是,页面通过微信公众号静默授权方式获取openId后,携带openId调用后端“获取自由职业者信息”接口。

后端程序是SSM框架:SohoSignController → SohoSignService → SohoSignDAO → SohoSignMapper.xml

@RestController class SohoSignController {
    @Autowired SohoSignService sohoSignService;
 
    @GetMapping("/sohosign")
    public Result sohoSign(String openId) {
        Map<String, Object> mapQuery = new HashMap<String, Object>();
        mapQuery.put("openId", openId);
        return Result.success(sohoSignService.selectSohoList(mapQuery));           
    }
}
 
@Service class SohoSignService {
    @Autowired SohoSignDAO sohoSignDAO;
     
    public List<Soho> selectSohoList(Map<String, Object> mapQuery) {
        return sohoSignDAO.selectSohoList(mapQuery);
    }
}
 
interface SohoSignDAO {
    List<Soho> selectSohoList(Map<String, Object> mapQuery);
}
 
SohoSignMapper.xml
    <select id="selectSohoList" parameterType="java.util.Map" resultMap="BaseResultMap">
        select *
        from t_soho a
        <where>
            <if test="mobile != null">
                and a.mobile = #{mobile}
            </if>
            <if test="openId != null">
                and a.open_id = #{openId}
            </if>
        </where>
        order by a.id desc
    </select>

t_soho表有300w+数据量,open_id字段上有索引。每个open_id存在10多条数据记录。因此,按openId查询数据没有性能问题。

代码看似正常。

突然某几天里,优付这个签约服务tomcat频繁出现假死和OOM。

后来经排查,才知道,有人直接访问了这个签约url——是的,没有传openId参数——这意味着什么?技术敏感的同学必然有答案。

 

posted on 2020-12-02 19:00  buguge  阅读(112)  评论(0编辑  收藏  举报