开始游戏bug:
表现:
我游戏服发送相同格式数据到网关服,游戏服日志显示已经发送到网关服,而网关服会偶然收不到数据,出现概率大概1/2,游戏服和网关服日志上均无报错,仅是网关服偶然收不到数据.
猜测1: 数据格式导致网关反序列化失败
测试: 用相同的序列化和反序列化在游戏服发送数据前,打印反序列话对象,结果反序列化成功,证明不是数据格式问题(ps: 该测试建立在bug出现时)
猜测2: 超时导致网关收不到数据
测试: 在bug出现时记录游戏服request->发送数据之间的时间,记录网关request->response之间时间,发现均未超过1分钟,框架设置超时为1分钟,日志也没报超时错误.
猜测3:哪一段代码运行出问题
测试: 调试代码,一行一行运行,未发现错误与无线循环
差不都到这里就没思路了....
在我调试另一个bug却发现了问题
玩家上线超时bug:
ps:该功能会发送给上线玩家一个数据,跟上一个bug相同的数据结构数据
猜测: 看看是不是哪里有循环出问题了
测试: 调试代码,终于发现了问题
2018-01-14 10:25:45.101 [BUSINESS-1-1] ERROR [] thread [BUSINESS-1-1] has a uncaught exception
java.lang.StackOverflowError
at java.util.ArrayList.iterator(ArrayList.java:834) ~[?:1.8.0_144]
at java.util.AbstractCollection.toString(AbstractCollection.java:454) ~[?:1.8.0_144]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.LandLordGamePlayer.toString(LandLordGamePlayer.java:255) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at java.util.AbstractCollection.toString(AbstractCollection.java:462) ~[?:1.8.0_144]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.LandLordGameData.toString(LandLordGameData.java:361) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.msg.LandLordGameStartMsg.toString(LandLordGameStartMsg.java:29) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.RoundData.toString(RoundData.java:48) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at java.util.AbstractCollection.toString(AbstractCollection.java:462) ~[?:1.8.0_144]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.LandLordGameData.toString(LandLordGameData.java:368) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.msg.LandLordGameStartMsg.toString(LandLordGameStartMsg.java:29) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.RoundData.toString(RoundData.java:48) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at java.util.AbstractCollection.toString(AbstractCollection.java:462) ~[?:1.8.0_144]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.LandLordGameData.toString(LandLordGameData.java:368) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.msg.LandLordGameStartMsg.toString(LandLordGameStartMsg.java:29) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.RoundData.toString(RoundData.java:48) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at java.util.AbstractCollection.toString(AbstractCollection.java:462) ~[?:1.8.0_144]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.LandLordGameData.toString(LandLordGameData.java:368) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.msg.LandLordGameStartMsg.toString(LandLordGameStartMsg.java:29) ~[bin/:?]
at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_144]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_144]
at com.landlord.lq.game.biz.game.landlord.domain.RoundData.toString(RoundData.java:48) ~[bin/:?]
我用roundData存放了LandLordGameStartMsg,LandLordGameStartMsg里面存放了LandLordGameData,msgId.而LandLordGameData里面却也存了roundData,所有导致嵌套循环,内存溢出,这个错误是在roundData的toString时报错,至于为什么开始游戏时没有报错,还不知道为什么,因为我删除存放LandLordGameStartMsg这句代码后,开始游戏正常,运行几十次后均无异常发生.
以前也没遇到过类似问题,经验不足,加上写代码时也没考虑到,导致出现这个问题,以后写代码一定得多注意
为什么开始有bug没有报StackOverFlow.......