|
1 | 1 | ---
|
2 |
| -title: Troubleshoot a "Request header too large" message or 400 bad request in Azure Cosmos DB |
3 |
| -description: Learn how to diagnose and fix the request header too large exception. |
| 2 | +title: Troubleshoot "request header too large" or "bad request" |
| 3 | +titleSuffix: Azure Cosmos DB |
| 4 | +description: Learn how to diagnose and fix either the HTTP request header too large or bad request (400) exceptions. |
4 | 5 | author: seesharprun
|
| 6 | +ms.author: sidandrews |
| 7 | +ms.reviewer: mjbrown |
5 | 8 | ms.service: cosmos-db
|
6 | 9 | ms.subservice: nosql
|
7 |
| -ms.date: 09/29/2021 |
8 |
| -ms.author: sidandrews |
9 | 10 | ms.topic: troubleshooting
|
10 |
| -ms.reviewer: mjbrown |
| 11 | +ms.date: 02/27/2023 |
11 | 12 | ms.custom: devx-track-dotnet, ignite-2022
|
12 | 13 | ---
|
13 | 14 |
|
14 |
| -# Diagnose and troubleshoot Azure Cosmos DB "Request header too large" message |
| 15 | +# Diagnose and troubleshoot "request header too large" or "bad request" messages in Azure Cosmos DB SDK for .NET |
| 16 | + |
15 | 17 | [!INCLUDE[NoSQL](../includes/appliesto-nosql.md)]
|
16 | 18 |
|
17 |
| -The "Request header too large" message is thrown with an HTTP error code 400. This error occurs if the size of the request header has grown so large that it exceeds the maximum-allowed size. We recommend that you use the latest version of the SDK. Use at least version 3.x or 2.x, because these versions add header size tracing to the exception message. |
| 19 | +The "Request header too large" message is thrown with an HTTP error code 400. This error occurs if the size of the request header has grown so large that it exceeds the maximum-allowed size. We recommend that you use the latest version of the Azure Cosmos DB SDK for .NET. We recommend that you use version 3.x because this major version adds header size tracing to the exception message. |
18 | 20 |
|
19 | 21 | ## Troubleshooting steps
|
| 22 | + |
20 | 23 | The "Request header too large" message occurs if the session or the continuation token is too large. The following sections describe the cause of the issue and its solution in each category.
|
21 | 24 |
|
22 | 25 | ### Session token is too large
|
23 | 26 |
|
24 |
| -#### Cause: |
| 27 | +This section reviews scenarios where the session token is too large. |
| 28 | + |
| 29 | +#### Cause |
| 30 | + |
25 | 31 | A 400 bad request most likely occurs because the session token is too large. If the following statements are true, the session token is too large:
|
26 | 32 |
|
27 | 33 | * The error occurs on point operations like create, read, and update where there isn't a continuation token.
|
28 | 34 | * The exception started without making any changes to the application. The session token grows as the number of partitions increases in the container. The number of partitions increases as the amount of data increases or if the throughput is increased.
|
29 | 35 |
|
30 |
| -#### Temporary mitigation: |
31 |
| -Restart your client application to reset all the session tokens. Eventually, the session token will grow back to the previous size that caused the issue. To avoid this issue completely, use the solution in the next section. |
| 36 | +#### Temporary mitigation |
| 37 | + |
| 38 | +Restart your client application to reset all the session tokens. Eventually, the session token grows back to the previous size that caused the issue. To avoid this issue completely, use the solution in the next section. |
| 39 | + |
| 40 | +#### Solution |
32 | 41 |
|
33 |
| -#### Solution: |
34 | 42 | > [!IMPORTANT]
|
35 | 43 | > Upgrade to at least .NET [v3.20.1](https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/changelog.md) or [v2.16.1](https://github.com/Azure/azure-cosmos-dotnet-v2/blob/master/changelog.md). These minor versions contain optimizations to reduce the session token size to prevent the header from growing and hitting the size limit.
|
| 44 | +
|
36 | 45 | 1. Follow the guidance in the [.NET v3](performance-tips-dotnet-sdk-v3.md) or [.NET v2](performance-tips.md) performance tips articles. Convert the application to use the direct connection mode with the Transmission Control Protocol (TCP). The direct connection mode with the TCP protocol doesn't have the header size restriction like the HTTP protocol, so it avoids this issue. Make sure to use the latest version of the SDK, which has a fix for query operations when the service interop isn't available.
|
37 | 46 | 1. If the direct connection mode with the TCP protocol isn't an option for your workload, mitigate it by changing the [client consistency level](how-to-manage-consistency.md). The session token is only used for session consistency, which is the default consistency level for Azure Cosmos DB. Other consistency levels don't use the session token.
|
38 | 47 |
|
39 | 48 | ### Continuation token is too large
|
40 | 49 |
|
41 |
| -#### Cause: |
42 |
| -The 400 bad request occurs on query operations where the continuation token is used if the continuation token has grown too large or if different queries have different continuation token sizes. |
43 |
| - |
44 |
| -#### Solution: |
45 |
| -1. Follow the guidance in the [.NET v3](performance-tips-dotnet-sdk-v3.md) or [.NET v2](performance-tips.md) performance tips articles. Convert the application to use the direct connection mode with the TCP protocol. The direct connection mode with the TCP protocol doesn't have the header size restriction like the HTTP protocol, so it avoids this issue. |
| 50 | +This section reviews scenarios where the continuation token is too large. |
| 51 | + |
| 52 | +#### Cause |
| 53 | + |
| 54 | +The 400 bad request occurs on query operations where the continuation token is used if the token has grown too large. This error can also occur if different queries have different continuation token sizes. |
| 55 | + |
| 56 | +#### Solution |
| 57 | + |
| 58 | +1. Follow the guidance in the [.NET v3](performance-tips-dotnet-sdk-v3.md) or [.NET v2](performance-tips.md) performance tips articles. Convert the application to use the direct connection mode with the TCP protocol. The direct connection mode with the TCP protocol doesn't have the header size restriction like the HTTP protocol, so it avoids this issue. |
46 | 59 | 1. If the direct connection mode with the TCP protocol isn't an option for your workload, set the `ResponseContinuationTokenLimitInKb` option. You can find this option in `FeedOptions` in v2 or `QueryRequestOptions` in v3.
|
47 | 60 |
|
48 | 61 | ## Next steps
|
| 62 | + |
49 | 63 | * [Diagnose and troubleshoot](troubleshoot-dotnet-sdk.md) issues when you use the Azure Cosmos DB .NET SDK.
|
50 | 64 | * Learn about performance guidelines for [.NET v3](performance-tips-dotnet-sdk-v3.md) and [.NET v2](performance-tips.md).
|
0 commit comments