• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19943

13 Aug 2025 09:23PM UTC coverage: 88.545% (-0.03%) from 88.573%
#19943

push

github

ejona86
Upgrade to Netty 4.1.124.Final

This implicitly disables NettyAdaptiveCumulator (#11284), which can have a
performance impact. We delayed upgrading Netty to give time to rework
the optimization, but we've gone too long already without upgrading
which causes problems for vulnerability tracking.

34659 of 39143 relevant lines covered (88.54%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.33
/../netty/src/main/java/io/grpc/netty/GrpcHttp2ConnectionHandler.java
1
/*
2
 * Copyright 2016 The gRPC Authors
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
 */
16

17
package io.grpc.netty;
18

19
import static com.google.common.base.Preconditions.checkState;
20

21
import com.google.common.annotations.VisibleForTesting;
22
import io.grpc.Attributes;
23
import io.grpc.ChannelLogger;
24
import io.grpc.Internal;
25
import io.grpc.InternalChannelz;
26
import io.netty.channel.ChannelPromise;
27
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
28
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
29
import io.netty.handler.codec.http2.Http2ConnectionHandler;
30
import io.netty.handler.codec.http2.Http2Settings;
31
import io.netty.util.Version;
32
import javax.annotation.Nullable;
33

34
/**
35
 * gRPC wrapper for {@link Http2ConnectionHandler}.
36
 */
37
@Internal
38
public abstract class GrpcHttp2ConnectionHandler extends Http2ConnectionHandler {
39
  static final int ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT = 1024;
40
  static final Cumulator ADAPTIVE_CUMULATOR =
1✔
41
      new NettyAdaptiveCumulator(ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT);
42

43
  @Nullable
44
  protected final ChannelPromise channelUnused;
45
  private final ChannelLogger negotiationLogger;
46
  private static final boolean usingPre4_1_111_Netty;
47

48
  static {
49
    // Netty 4.1.111 introduced a change in the behavior of duplicate() method
50
    // that breaks the assumption of the cumulator. We need to detect this version
51
    // and adjust the behavior accordingly.
52

53
    boolean identifiedOldVersion = false;
1✔
54
    try {
55
      Version version = Version.identify().get("netty-buffer");
1✔
56
      if (version != null) {
1✔
57
        String[] split = version.artifactVersion().split("\\.");
1✔
58
        if (split.length >= 3
1✔
59
            && Integer.parseInt(split[0]) == 4
1✔
60
            && Integer.parseInt(split[1]) <= 1
1✔
61
            && Integer.parseInt(split[2]) < 111) {
1✔
62
          identifiedOldVersion = true;
×
63
        }
64
      }
65
    } catch (Exception e) {
×
66
      // Ignore, we'll assume it's a new version.
67
    }
1✔
68
    usingPre4_1_111_Netty = identifiedOldVersion;
1✔
69
  }
1✔
70

71
  protected GrpcHttp2ConnectionHandler(
72
      ChannelPromise channelUnused,
73
      Http2ConnectionDecoder decoder,
74
      Http2ConnectionEncoder encoder,
75
      Http2Settings initialSettings,
76
      ChannelLogger negotiationLogger) {
77
    super(decoder, encoder, initialSettings);
1✔
78
    this.channelUnused = channelUnused;
1✔
79
    this.negotiationLogger = negotiationLogger;
1✔
80
    if (usingPre4_1_111_Netty()) {
1✔
81
      // We need to use the adaptive cumulator only if we're using a version of Netty that
82
      // doesn't have the behavior that breaks it.
83
      setCumulator(ADAPTIVE_CUMULATOR);
×
84
    }
85
  }
1✔
86

87
  @VisibleForTesting
88
  static boolean usingPre4_1_111_Netty() {
89
    return usingPre4_1_111_Netty;
1✔
90
  }
91

92
  /**
93
   * Same as {@link #handleProtocolNegotiationCompleted(
94
   *   Attributes, io.grpc.InternalChannelz.Security)}
95
   * but with no {@link io.grpc.InternalChannelz.Security}.
96
   *
97
   * @deprecated Use the two argument method instead.
98
   */
99
  @Deprecated
100
  @SuppressWarnings("InlineMeSuggester") // the caller should consider providing securityInfo
101
  public void handleProtocolNegotiationCompleted(Attributes attrs) {
102
    handleProtocolNegotiationCompleted(attrs, /*securityInfo=*/ null);
×
103
  }
×
104

105
  /**
106
   * Triggered on protocol negotiation completion.
107
   *
108
   * <p>It must me called after negotiation is completed but before given handler is added to the
109
   * channel.
110
   *
111
   * @param attrs arbitrary attributes passed after protocol negotiation (eg. SSLSession).
112
   * @param securityInfo informs channelz about the security protocol.
113
   */
114
  public void handleProtocolNegotiationCompleted(
115
      Attributes attrs, InternalChannelz.Security securityInfo) {
116
  }
1✔
117

118
  /**
119
   * Returns the channel logger for the given channel context.
120
   */
121
  public ChannelLogger getNegotiationLogger() {
122
    checkState(negotiationLogger != null, "NegotiationLogger must not be null");
1✔
123
    return negotiationLogger;
1✔
124
  }
125

126
  /**
127
   * Calling this method indicates that the channel will no longer be used.  This method is roughly
128
   * the same as calling {@link #close} on the channel, but leaving the channel alive.  This is
129
   * useful if the channel will soon be deregistered from the executor and used in a non-Netty
130
   * context.
131
   */
132
  @SuppressWarnings("FutureReturnValueIgnored")
133
  public void notifyUnused() {
134
    channelUnused.setSuccess(null);
×
135
  }
×
136

137
  /** Get the attributes of the EquivalentAddressGroup used to create this transport. */
138
  public Attributes getEagAttributes() {
139
    return Attributes.EMPTY;
1✔
140
  }
141

142
  /**
143
   * Returns the authority of the server. Only available on the client-side.
144
   *
145
   * @throws UnsupportedOperationException if on server-side
146
   */
147
  public String getAuthority() {
148
    throw new UnsupportedOperationException();
×
149
  }
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc