今天在排查实习生写的代码,发现dubbo的服务被调用了2次,第一次把数据给请掉了,但是没有返回成功,第二次直接提示数据不存在,导致服务不能用。
基于这个场景,以为是调用时间太长,触发了重复调用
@Service(version = "${provider.service.version}", timeout = 10000, retries = 0)
就在服务提供上加了10s的延迟,不重复调用
这次报错了:
大概如下:
"result": "Failed to invoke the method loginAction in the service com.coolwell.vehicle.remote.monitor.contract.contract.LoginService. Tried 1 times of the providers [] (1/1) from the registry tsp-zookeeper:2181 on the consumer x using the dubbo version 2.7.6. Last error is: Failed to invoke remote method: loginAction, provider: dubbo://x:20990/com.coolwell.vehicle.remote.monitor.contract.contract.LoginService?anyhost=true&application=coocaa-tsp-web&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=com.coolwell.vehicle.remote.monitor.contract.contract.LoginService&methods=getCurrentLoginUser,loginAction,checkToken,randomImage,loginOutAction&pid=1&qos.enable=false®ister.ip=tsp-zookeeper&release=2.7.6&remote.application=coolwell-remote-monitor&retries=0&revision=1.0.0&side=consumer&sticky=false&timeout=30000×tamp=1686715947949&version=1.0.0, cause: org.apache.dubbo.remoting.RemotingException: Failed to send response: Response [id=408, version=2.0.2, status=20, event=false, error=null, result=AppResponse [value=com.coocaa.tsp.common.utils.ApiMessage@94bf6b1, exception=null]], cause: java.lang.RuntimeException: Serialized class com.coolwell.vehicle.remote.monitor.contract.entity.login.LoginUser must implement java.io.Serializable\n Java field: private java.lang.Object com.coocaa.tsp.common.utils.ApiMessage.result\njava.lang.RuntimeException: Serialized class com.coolwell.vehicle.remote.monitor.contract.entity.login.LoginUser must implement java.io.Serializable\n Java field: private java.lang.Object com.coocaa.tsp.common.utils.ApiMessage.result\n\tat com.alibaba.com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:304)\n\tat
看到这个报错,一眼可以看出来,是dubbo调用的时候就报错了:
com.coolwell.vehicle.remote.monitor.contract.entity.login.LoginUser must implement java.io.Serializable
这短话,定位到问题,应该是定义了实体类,但是没有序列化,提示必须要序列化
就修改一下
public class LoginUser implements Serializable {private static final long serialVersionUID = -1L;
重启服务,发现正常使用,在实体类中,如果涉及到传输,io还是要做序列化的。