Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复dubbox两个bug #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* www.yiji.com Inc.
* Copyright (c) 2015 All Rights Reserved
*/

package com.alibaba.dubbo.remoting;

import java.io.IOException;

/**
* @author bohr.qiu@gmail.com
*/
public class DataTooLargeException extends IOException {

public DataTooLargeException() {
super();
}

public DataTooLargeException(String message) {
super(message);
}

public DataTooLargeException(String message, Throwable cause) {
super(message, cause);
}

public DataTooLargeException(Throwable cause) {
super(cause);
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alibaba.dubbo.common.serialize.Serialization; import com.alibaba.dubbo.common.serialize.Serialization;
import com.alibaba.dubbo.common.utils.StringUtils; import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.remoting.Channel; import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.DataTooLargeException;
import com.alibaba.dubbo.remoting.RemotingException; import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.buffer.ChannelBuffer; import com.alibaba.dubbo.remoting.buffer.ChannelBuffer;
import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream;
Expand Down Expand Up @@ -315,18 +316,34 @@ protected void encodeResponse(Channel channel, ChannelBuffer buffer, Response re
} catch (Throwable t) { } catch (Throwable t) {
// 发送失败信息给Consumer,否则Consumer只能等超时了 // 发送失败信息给Consumer,否则Consumer只能等超时了
if (! res.isEvent() && res.getStatus() != Response.BAD_RESPONSE) { if (! res.isEvent() && res.getStatus() != Response.BAD_RESPONSE) {
try { if(t instanceof DataTooLargeException){
// FIXME 在Codec中打印出错日志?在IoHanndler的caught中统一处理? try {
logger.warn("Fail to encode response: " + res + ", send bad_response info instead, cause: " + t.getMessage(), t); // FIXME 在Codec中打印出错日志?在IoHanndler的caught中统一处理?

logger.warn("Fail to encode response, send bad_response info instead, cause: " + t.getMessage(), t);
Response r = new Response(res.getId(), res.getVersion());
r.setStatus(Response.BAD_RESPONSE); Response r = new Response(res.getId(), res.getVersion());
r.setErrorMessage("Failed to send response: " + res + ", cause: " + StringUtils.toString(t)); r.setStatus(Response.BAD_RESPONSE);
channel.send(r); r.setErrorMessage("Failed to send response, cause: " + StringUtils.toString(t));

channel.send(r);
return;
} catch (RemotingException e) { return;
logger.warn("Failed to send bad_response info back: " + res + ", cause: " + e.getMessage(), e); } catch (RemotingException e) {
logger.warn("Failed to send bad_response info back:, cause: " + e.getMessage(), e);
}
}else{
try {
// FIXME 在Codec中打印出错日志?在IoHanndler的caught中统一处理?
logger.warn("Fail to encode response: " + res + ", send bad_response info instead, cause: " + t.getMessage(), t);

Response r = new Response(res.getId(), res.getVersion());
r.setStatus(Response.BAD_RESPONSE);
r.setErrorMessage("Failed to send response: " + res + ", cause: " + StringUtils.toString(t));
channel.send(r);

return;
} catch (RemotingException e) {
logger.warn("Failed to send bad_response info back: " + res + ", cause: " + e.getMessage(), e);
}
} }
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.alibaba.dubbo.common.utils.NetUtils; import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.remoting.Channel; import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.Codec2; import com.alibaba.dubbo.remoting.Codec2;
import com.alibaba.dubbo.remoting.DataTooLargeException;


/** /**
* AbstractCodec * AbstractCodec
Expand All @@ -46,7 +47,7 @@ protected static void checkPayload(Channel channel, long size) throws IOExceptio
payload = channel.getUrl().getParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD); payload = channel.getUrl().getParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD);
} }
if (payload > 0 && size > payload) { if (payload > 0 && size > payload) {
IOException e = new IOException("Data length too large: " + size + ", max payload: " + payload + ", channel: " + channel); DataTooLargeException e = new DataTooLargeException("Data length too large: " + size + ", max payload: " + payload + ", channel: " + channel);
logger.error(e); logger.error(e);
throw e; throw e;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ public void decode() throws Exception {
if (!hasDecoded && channel != null && inputStream != null) { if (!hasDecoded && channel != null && inputStream != null) {
try { try {
decode(channel, inputStream); decode(channel, inputStream);
} catch (Throwable e) {
if (log.isWarnEnabled()) {
log.warn("Decode rpc invocation failed: " + e.getMessage(), e);
}
request.setBroken(true);
request.setData(e);
} finally { } finally {
hasDecoded = true; hasDecoded = true;
} }
Expand Down Expand Up @@ -112,14 +106,8 @@ public Object decode(Channel channel, InputStream input) throws IOException {
args = new Object[argNum]; args = new Object[argNum];
pts = new Class[argNum]; pts = new Class[argNum];
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
try { args[i] = in.readObject();
args[i] = in.readObject(); pts[i] = args[i].getClass();
pts[i] = args[i].getClass();
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Decode argument failed: " + e.getMessage(), e);
}
}
} }
} }
} else { } else {
Expand All @@ -131,13 +119,7 @@ public Object decode(Channel channel, InputStream input) throws IOException {
pts = ReflectUtils.desc2classArray(desc); pts = ReflectUtils.desc2classArray(desc);
args = new Object[pts.length]; args = new Object[pts.length];
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
try { args[i] = in.readObject(pts[i]);
args[i] = in.readObject(pts[i]);
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Decode argument failed: " + e.getMessage(), e);
}
}
} }
} }
} }
Expand Down