Skip to content

Our customized serialization id exceeds the maximum limit, now it cannot work on 2.6.2 anymore. #1903

Closed

Description

@linzhiqiang0514

前提:
我们自定义了序列化方式,serialization.getContentTypeId() == 88
超出计算的最大值。
按照ExchangeCodec的逻辑,这个值最大允许32。
88在服务端经过计算,变成24,无法获取到序列化方式。

在2.6.0版本时,获取序列化方式,采用兼容处理
CodecSupport.java代码如下:

public static Serialization getSerialization(URL url) {
        return ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(
                url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION));
    }

    public static Serialization getSerialization(URL url, Byte id) {
        Serialization result = getSerializationById(id);
        if (result == null) {
            result = getSerialization(url);
        }
        return result;
    }

上述代码会从SPI接口,根据url获取的参数,进一步获取。

在2.6.2版本时,获取序列化方式更改,根据id获取不到则抛出异常

public static Serialization getSerialization(URL url, Byte id) throws IOException {
        Serialization serialization = getSerializationById(id);
        String serializationName = url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
        // Check if "serialization id" passed from network matches the id on this side(only take effect for JDK serialization), for security purpose.
        if (serialization == null
                || ((id == 3 || id == 7 || id == 4) && !(serializationName.equals(ID_SERIALIZATIONNAME_MAP.get(id))))) {
            throw new IOException("Unexpected serialization id:" + id + " received from network, please check if the peer send the right id.");
        }
        return serialization;
    }

异常抛出后,没有做处理,导致的服务端hang住不返回,需要等待超时报错。代码在如下位置:
com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.decode(Channel, ChannelBuffer, int, byte[]) Line:124

try {
            return decodeBody(channel, is, header);
        } finally {
            if (is.available() > 0) {
                try {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Skip input stream " + is.available());
                    }
                    StreamUtils.skipUnusedStream(is);
                } catch (IOException e) {
                    logger.warn(e.getMessage(), e);
                }
            }
        }
    }

    protected Object decodeBody(Channel channel, InputStream is, byte[] header) throws IOException {
        byte flag = header[2], proto = (byte) (flag & SERIALIZATION_MASK);
        Serialization s = CodecSupport.getSerialization(channel.getUrl(), proto);
        ObjectInput in = s.deserialize(channel.getUrl(), is);

Line:141 抛出异常.
Line:124 不做处理。

导致服务不返回。

Activity

  1. changed the title [-]升级2.6.2版本后,自定义序列化方式出现hang住的情况。[/-] [+]Our customized serialization id exceeds the maximum limit, now it cannot work on 2.6.2 anymore.[/+] on Jun 11, 2018
  2. chickenlj commented on Jun 11, 2018

    @chickenlj
    Contributor

    我们自定义了序列化方式,serialization.getContentTypeId() == 88
    超出计算的最大值。
    按照ExchangeCodec的逻辑,这个值最大允许32。
    88在服务端经过计算,变成24,无法获取到序列化方式。

    The maximum id limit seems to be 31.
    Your customized id 88 exceeds the limit and was decoded to 24, what if there's a serialization type for id 24? I think a reasonable value below 32 should be used to replace 88.

    异常抛出后,没有做处理,导致的服务端hang住不返回,需要等待超时报错。代码在如下位置:
    com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.decode(Channel, ChannelBuffer, int, byte[]) Line:124

    I think Dubbo should send the serialization error back to consumer, i will check this problem further.

  3. added
    type/bug
    on Jul 10, 2018
  4. added this to the 2.6.3 milestone on Jul 10, 2018
  5. modified the milestones: 2.6.3, 2.6.4 on Jul 23, 2018
  6. modified the milestones: 2.6.4, 2.6.5 on Sep 14, 2018
  7. added 2 commits that reference this issue on Oct 21, 2018
  8. added 8 commits that reference this issue on Dec 6, 2018
    999d34b
    22099b3
    5c8827f
    19e2886
    648794e
    ffa18c9
    747e9da
    9ec86f8
  9. added a commit that references this issue on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

type/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions