From d82cc29d0cbb954f9d9274530a84cd761b6f4482 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 28 Jul 2014 10:12:49 -0700 Subject: [PATCH] [#2706] Allow pid up to 4194304 Motivation: The PID_MAX_LIMIT on 64bit linux systems is 4194304 and on osx it is 99998. At the moment we use 65535 as an upper-limit which is too small. Modifications: Use 4194304 as max possible value Result: No more false-positives when try to detect current pid. --- .../java/io/netty/channel/DefaultChannelId.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelId.java b/transport/src/main/java/io/netty/channel/DefaultChannelId.java index fb0e67b042..fdc55b0b4e 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelId.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelId.java @@ -49,8 +49,10 @@ final class DefaultChannelId implements ChannelId { private static final Pattern MACHINE_ID_PATTERN = Pattern.compile("^(?:[0-9a-fA-F][:-]?){6,8}$"); private static final int MACHINE_ID_LEN = 8; private static final byte[] MACHINE_ID; - private static final int PROCESS_ID_LEN = 2; - private static final int MAX_PROCESS_ID = 65535; + private static final int PROCESS_ID_LEN = 4; + // Maximal value for 64bit systems is 2^22. See man 5 proc. + // See https://github.com/netty/netty/issues/2706 + private static final int MAX_PROCESS_ID = 4194304; private static final int PROCESS_ID; private static final int SEQUENCE_LEN = 4; private static final int TIMESTAMP_LEN = 8; @@ -362,7 +364,7 @@ final class DefaultChannelId implements ChannelId { i += MACHINE_ID_LEN; // processId - i = writeShort(i, PROCESS_ID); + i = writeInt(i, PROCESS_ID); // sequence i = writeInt(i, nextSequence.getAndIncrement()); @@ -378,12 +380,6 @@ final class DefaultChannelId implements ChannelId { assert i == data.length; } - private int writeShort(int i, int value) { - data[i ++] = (byte) (value >>> 8); - data[i ++] = (byte) value; - return i; - } - private int writeInt(int i, int value) { data[i ++] = (byte) (value >>> 24); data[i ++] = (byte) (value >>> 16);