Skip to content

Commit 4eccef5

Browse files
lalernehlalaborda
andauthored
Fix header size exceeded error (#1967)
Co-authored-by: alaborda <[email protected]>
1 parent 3e71ada commit 4eccef5

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

zuul-core/src/main/java/com/netflix/zuul/exception/OutboundErrorType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public enum OutboundErrorType implements ErrorType {
6464
ERROR_TYPE_ORIGIN_CONCURRENCY_EXCEEDED_STATUS.get(),
6565
ZuulStatusCategory.FAILURE_LOCAL_THROTTLED_ORIGIN_CONCURRENCY,
6666
ClientException.ErrorType.SERVER_THROTTLED),
67+
HEADER_FIELDS_TOO_LARGE(431, ZuulStatusCategory.FAILURE_LOCAL_HEADER_FIELDS_TOO_LARGE, ClientException.ErrorType.GENERAL),
6768
OTHER(ERROR_TYPE_OTHER_STATUS.get(), ZuulStatusCategory.FAILURE_LOCAL, ClientException.ErrorType.GENERAL);
6869

6970
private static final String NAME_PREFIX = "ORIGIN_";

zuul-core/src/main/java/com/netflix/zuul/netty/NettyRequestAttemptFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.netflix.zuul.niws.RequestAttempts;
2525
import com.netflix.zuul.origins.OriginConcurrencyExceededException;
2626
import io.netty.channel.unix.Errors;
27+
import io.netty.handler.codec.http2.Http2Exception.HeaderListSizeException;
2728
import io.netty.handler.timeout.ReadTimeoutException;
2829
import java.nio.channels.ClosedChannelException;
2930
import org.slf4j.Logger;
@@ -62,6 +63,10 @@ public ErrorType mapNettyToOutboundErrorType(Throwable t) {
6263
return OutboundErrorType.RESET_CONNECTION;
6364
}
6465

66+
if (t instanceof HeaderListSizeException) {
67+
return OutboundErrorType.HEADER_FIELDS_TOO_LARGE;
68+
}
69+
6570
Throwable cause = t.getCause();
6671
if (cause instanceof IllegalStateException && cause.getMessage().contains("server")) {
6772
LOG.warn("IllegalStateException mapped to NO_AVAILABLE_SERVERS", cause);

zuul-core/src/main/java/com/netflix/zuul/stats/status/ZuulStatusCategory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public enum ZuulStatusCategory implements StatusCategory {
6060
FAILURE_LOCAL_THROTTLED_ORIGIN_CONCURRENCY(
6161
ZuulStatusCategoryGroup.FAILURE, 8, "Throttled due to reaching concurrency limit to origin"),
6262
FAILURE_LOCAL_IDLE_TIMEOUT(ZuulStatusCategoryGroup.FAILURE, 9, "Idle timeout due to channel inactivity"),
63-
63+
FAILURE_LOCAL_HEADER_FIELDS_TOO_LARGE(ZuulStatusCategoryGroup.FAILURE, 5, "Header Fields Too Large"),
6464
FAILURE_CLIENT_BAD_REQUEST(ZuulStatusCategoryGroup.FAILURE, 12, "Invalid request provided"),
6565
FAILURE_CLIENT_CANCELLED(ZuulStatusCategoryGroup.FAILURE, 13, "Client abandoned/closed the connection"),
6666
FAILURE_CLIENT_PIPELINE_REJECT(ZuulStatusCategoryGroup.FAILURE, 17, "Client rejected due to HTTP Pipelining"),
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2018 Netflix, Inc.
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 com.netflix.zuul.netty;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import com.netflix.zuul.context.SessionContext;
22+
import com.netflix.zuul.exception.OutboundErrorType;
23+
import com.netflix.zuul.exception.OutboundException;
24+
import com.netflix.zuul.netty.connectionpool.OriginConnectException;
25+
import com.netflix.zuul.niws.RequestAttempts;
26+
import com.netflix.zuul.origins.OriginConcurrencyExceededException;
27+
import com.netflix.zuul.origins.OriginName;
28+
import io.netty.handler.codec.http2.Http2Error;
29+
import io.netty.handler.codec.http2.Http2Exception;
30+
import io.netty.handler.timeout.ReadTimeoutException;
31+
import java.nio.channels.ClosedChannelException;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
34+
35+
public class NettyRequestAttemptFactoryTest {
36+
private NettyRequestAttemptFactory factory;
37+
38+
@BeforeEach
39+
public void setup() {
40+
factory = new NettyRequestAttemptFactory();
41+
}
42+
43+
@Test
44+
public void mapNettyToOutboundExceptionMapsToOutboundException() {
45+
Exception e = new OutboundException(OutboundErrorType.OTHER,
46+
new RequestAttempts());
47+
OutboundException mapException = factory.mapNettyToOutboundException(e, new SessionContext());
48+
49+
assertEquals(e, mapException);
50+
// check that the type is OutboundException
51+
assertNotNull(mapException);
52+
}
53+
54+
@Test
55+
public void mapNettyToOutboundExceptionMapsToReadTimeoutException() {
56+
OutboundException mapException = factory.mapNettyToOutboundException(new ReadTimeoutException(), new SessionContext());
57+
58+
// check that the type is OutboundException
59+
assertNotNull(mapException);
60+
assertEquals(OutboundErrorType.READ_TIMEOUT, mapException.getOutboundErrorType());
61+
}
62+
63+
@Test
64+
public void mapNettyToOutboundExceptionMapsToOriginConcurrencyExceededException() {
65+
OutboundException mapException = factory.mapNettyToOutboundException(new OriginConcurrencyExceededException(OriginName.fromVipAndApp("vip", "app")), new SessionContext());
66+
67+
// check that the type is OutboundException
68+
assertNotNull(mapException);
69+
assertEquals(OutboundErrorType.ORIGIN_CONCURRENCY_EXCEEDED, mapException.getOutboundErrorType());
70+
}
71+
72+
@Test
73+
public void mapNettyToOutboundExceptionMapsToOriginConnectException() {
74+
OutboundException mapException = factory.mapNettyToOutboundException(new OriginConnectException("error",
75+
OutboundErrorType.OTHER), new SessionContext());
76+
77+
// check that the type is OutboundException
78+
assertNotNull(mapException);
79+
assertEquals(OutboundErrorType.OTHER, mapException.getOutboundErrorType());
80+
}
81+
82+
@Test
83+
public void mapNettyToOutboundExceptionMapsToClosedChannelException() {
84+
OutboundException mapException = factory.mapNettyToOutboundException(new ClosedChannelException(), new SessionContext());
85+
86+
// check that the type is OutboundException
87+
assertNotNull(mapException);
88+
assertEquals(OutboundErrorType.RESET_CONNECTION, mapException.getOutboundErrorType());
89+
}
90+
91+
@Test
92+
public void mapNettyToOutboundExceptionMapsToHeaderListSizeException() {
93+
OutboundException mapException = factory.mapNettyToOutboundException(Http2Exception.headerListSizeError(1, Http2Error.CONNECT_ERROR, false, ""), new SessionContext());
94+
95+
// check that the type is OutboundException
96+
assertNotNull(mapException);
97+
assertEquals(OutboundErrorType.HEADER_FIELDS_TOO_LARGE, mapException.getOutboundErrorType());
98+
}
99+
100+
@Test
101+
public void mapNettyToOutboundExceptionMapsToIllegalStateException() {
102+
OutboundException mapException = factory.mapNettyToOutboundException(new Exception(new IllegalStateException(new Throwable("No available server"))), new SessionContext());
103+
104+
// check that the type is OutboundException
105+
assertNotNull(mapException);
106+
assertEquals(OutboundErrorType.NO_AVAILABLE_SERVERS, mapException.getOutboundErrorType());
107+
}
108+
109+
@Test
110+
public void mapNettyToOutboundExceptionMapsToOtherExceptionType() {
111+
OutboundException mapException = factory.mapNettyToOutboundException(new Exception(), new SessionContext());
112+
113+
// check that the type is OutboundException
114+
assertNotNull(mapException);
115+
assertEquals(OutboundErrorType.OTHER, mapException.getOutboundErrorType());
116+
}
117+
}

0 commit comments

Comments
 (0)