Abhishek Kumar | 516d26e | 2016-02-01 16:40:09 -0800 | [diff] [blame] | 1 | # Status codes and their use in gRPC |
| 2 | |
Mark D. Roth | 2a86d3f | 2017-04-12 12:52:47 -0700 | [diff] [blame] | 3 | gRPC uses a set of well defined status codes as part of the RPC API. All |
| 4 | RPCs started at a client return a `status` object composed of an integer |
| 5 | `code` and a string `message`. The server-side can choose the status it |
| 6 | returns for a given RPC. |
Abhishek Kumar | 516d26e | 2016-02-01 16:40:09 -0800 | [diff] [blame] | 7 | |
Mark D. Roth | 2a86d3f | 2017-04-12 12:52:47 -0700 | [diff] [blame] | 8 | The gRPC client and server-side implementations may also generate and |
| 9 | return `status` on their own when errors happen. Only a subset of |
| 10 | the pre-defined status codes are generated by the gRPC libraries. This |
| 11 | allows applications to be sure that any other code it sees was actually |
| 12 | returned by the application (although it is also possible for the |
| 13 | server-side to return one of the codes generated by the gRPC libraries). |
| 14 | |
| 15 | The following table lists the codes that may be returned by the gRPC |
| 16 | libraries (on either the client-side or server-side) and summarizes the |
| 17 | situations in which they are generated. |
Abhishek Kumar | 516d26e | 2016-02-01 16:40:09 -0800 | [diff] [blame] | 18 | |
Abhishek Kumar | 80410eb | 2016-02-02 16:14:57 -0800 | [diff] [blame] | 19 | | Case | Code | Generated at Client or Server | |
Abhishek Kumar | 516d26e | 2016-02-01 16:40:09 -0800 | [diff] [blame] | 20 | | ------------- |:-------------| :-----:| |
Abhishek Kumar | 80410eb | 2016-02-02 16:14:57 -0800 | [diff] [blame] | 21 | | Client Application cancelled the request | CANCELLED | Both | |
| 22 | | Deadline expires before server returns status | DEADLINE_EXCEEDED | Both | |
| 23 | | Method not found at server | UNIMPLEMENTED | Server| |
| 24 | | Server shutting down | UNAVAILABLE | Server| |
| 25 | | Server side application throws an exception (or does something other than returning a Status code to terminate an RPC) | UNKNOWN | Server| |
| 26 | | No response received before Deadline expires. This may occur either when the client is unable to send the request to the server or when the server fails to respond in time. | DEADLINE_EXCEEDED | Both| |
| 27 | | Some data transmitted (e.g., request metadata written to TCP connection) before connection breaks | UNAVAILABLE | Client | |
| 28 | | Could not decompress, but compression algorithm supported (Client -> Server) | INTERNAL | Server | |
| 29 | | Could not decompress, but compression algorithm supported (Server -> Client) | INTERNAL | Client | |
| 30 | | Compression mechanism used by client not supported at server | UNIMPLEMENTED | Server | |
| 31 | | Server temporarily out of resources (e.g., Flow-control resource limits reached) | RESOURCE_EXHAUSTED | Server| |
Muxi Yan | fc99ff6 | 2016-07-06 15:08:30 -0700 | [diff] [blame] | 32 | | Client does not have enough memory to hold the server response | RESOURCE_EXHAUSTED | Client | |
Abhishek Kumar | 80410eb | 2016-02-02 16:14:57 -0800 | [diff] [blame] | 33 | | Flow-control protocol violation | INTERNAL | Both | |
| 34 | | Error parsing returned status | UNKNOWN | Client | |
| 35 | | Incorrect Auth metadata ( Credentials failed to get metadata, Incompatible credentials set on channel and call, Invalid host set in `:authority` metadata, etc.) | UNAUTHENTICATED | Both | |
Nathaniel Manista | c9dc834 | 2016-06-09 18:57:14 +0000 | [diff] [blame] | 36 | | Request cardinality violation (method requires exactly one request but client sent some other number of requests) | UNIMPLEMENTED | Server| |
| 37 | | Response cardinality violation (method requires exactly one response but server sent some other number of responses) | UNIMPLEMENTED | Client| |
Abhishek Kumar | 80410eb | 2016-02-02 16:14:57 -0800 | [diff] [blame] | 38 | | Error parsing response proto | INTERNAL | Client| |
| 39 | | Error parsing request proto | INTERNAL | Server| |
Mark D. Roth | 2a86d3f | 2017-04-12 12:52:47 -0700 | [diff] [blame] | 40 | | Sent or received message was larger than configured limit | RESOURCE_EXHAUSTED | Both | |
Yash Tibrewal | 4ec08f7 | 2018-07-23 17:01:00 -0700 | [diff] [blame] | 41 | | Keepalive watchdog times out | INTERNAL | Both | |
Abhishek Kumar | 516d26e | 2016-02-01 16:40:09 -0800 | [diff] [blame] | 42 | |
| 43 | The following status codes are never generated by the library: |
Abhishek Kumar | 80410eb | 2016-02-02 16:14:57 -0800 | [diff] [blame] | 44 | - INVALID_ARGUMENT |
| 45 | - NOT_FOUND |
| 46 | - ALREADY_EXISTS |
| 47 | - FAILED_PRECONDITION |
| 48 | - ABORTED |
| 49 | - OUT_OF_RANGE |
| 50 | - DATA_LOSS |
Yash Tibrewal | 4ec08f7 | 2018-07-23 17:01:00 -0700 | [diff] [blame] | 51 | |
Yash Tibrewal | 600272c | 2018-07-24 11:15:10 -0700 | [diff] [blame] | 52 | Applications that may wish to [retry](https://github.com/grpc/proposal/blob/master/A6-client-retries.md) failed RPCs must decide which status codes on which to retry. As shown in the table above, the gRPC library can generate the same status code for different cases. Server applications can also return those same status codes. Therefore, there is no fixed list of status codes on which it is appropriate to retry in all applications. As a result, individual applications must make their own determination as to which status codes should cause an RPC to be retried. |