Skip to content

Commit 7dd34d5

Browse files
committed
DUBBO-625 业务对象的toString方法异常会导致RemotingInvocationTimeoutScan失效
1 parent 2d73e4f commit 7dd34d5

File tree

1 file changed

+57
-44
lines changed
  • dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange

1 file changed

+57
-44
lines changed
Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
/*
2-
* Copyright 1999-2011 Alibaba Group.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
/*
2+
* Copyright 1999-2011 Alibaba Group.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616
package com.alibaba.dubbo.remoting.exchange;
1717

1818
import java.util.concurrent.atomic.AtomicLong;
1919

20+
import com.alibaba.dubbo.common.utils.StringUtils;
21+
2022
/**
2123
* Request.
2224
*
2325
* @author qian.lei
2426
* @author william.liangf
2527
*/
26-
public class Request {
27-
28-
public static final String HEARTBEAT_EVENT = null;
29-
30-
public static final String READONLY_EVENT = "R";
31-
28+
public class Request {
29+
30+
public static final String HEARTBEAT_EVENT = null;
31+
32+
public static final String READONLY_EVENT = "R";
33+
3234
private static final AtomicLong INVOKE_ID = new AtomicLong(0);
3335

3436
private final long mId;
3537

3638
private String mVersion;
3739

38-
private boolean mTwoWay = true;
39-
40+
private boolean mTwoWay = true;
41+
4042
private boolean mEvent = false;
4143

4244
private boolean mBroken = false;
@@ -70,15 +72,15 @@ public boolean isTwoWay() {
7072
public void setTwoWay(boolean twoWay) {
7173
mTwoWay = twoWay;
7274
}
73-
74-
public boolean isEvent() {
75-
return mEvent;
76-
}
77-
78-
public void setEvent(String event) {
79-
mEvent = true;
80-
mData = event;
81-
}
75+
76+
public boolean isEvent() {
77+
return mEvent;
78+
}
79+
80+
public void setEvent(String event) {
81+
mEvent = true;
82+
mData = event;
83+
}
8284

8385
public boolean isBroken() {
8486
return mBroken;
@@ -95,16 +97,16 @@ public Object getData() {
9597
public void setData(Object msg) {
9698
mData = msg;
9799
}
98-
99-
public boolean isHeartbeat() {
100-
return mEvent && HEARTBEAT_EVENT == mData;
101-
}
102-
103-
public void setHeartbeat(boolean isHeartbeat) {
104-
if (isHeartbeat) {
105-
setEvent(HEARTBEAT_EVENT);
106-
}
107-
}
100+
101+
public boolean isHeartbeat() {
102+
return mEvent && HEARTBEAT_EVENT == mData;
103+
}
104+
105+
public void setHeartbeat(boolean isHeartbeat) {
106+
if (isHeartbeat) {
107+
setEvent(HEARTBEAT_EVENT);
108+
}
109+
}
108110

109111
private static long newId() {
110112
// getAndIncrement()增长到MAX_VALUE时,再增长会变为MIN_VALUE,负数也可以做为ID
@@ -114,7 +116,18 @@ private static long newId() {
114116
@Override
115117
public String toString() {
116118
return "Request [id=" + mId + ", version=" + mVersion + ", twoway=" + mTwoWay + ", event=" + mEvent
117-
+ ", broken=" + mBroken + ", data=" + (mData == this ? "this" : mData) + "]";
119+
+ ", broken=" + mBroken + ", data=" + (mData == this ? "this" : safeToString(mData)) + "]";
118120
}
119121

120-
}
122+
private static String safeToString(Object data) {
123+
if (data == null) return null;
124+
String dataStr;
125+
try {
126+
dataStr = data.toString();
127+
} catch (Throwable e) {
128+
dataStr = "<Fail toString of " + data.getClass() + ", cause: " +
129+
StringUtils.toString(e) + ">";
130+
}
131+
return dataStr;
132+
}
133+
}

0 commit comments

Comments
 (0)