You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/08/04 15:05:07 UTC
[GitHub] [trafficcontrol] ocket8888 opened a new issue #6080: /types swallows errors/returns unhelpful error messages
ocket8888 opened a new issue #6080:
URL: https://github.com/apache/trafficcontrol/issues/6080
## I'm submitting a ...
- bug report
## Traffic Control components affected ...
- Traffic Ops
## Current behavior:
The `/types` API endpoint swallows any errors it encounters determining if a Type can be created/updated/deleted, and will return a "400 Bad Request" no matter what the encountered error was. This includes both user and system errors. For example, if making a perfectly valid PUT request that fails because DB timeout occurs, the response will be just a 400 Bad Request:
```http
PUT /api/3.0/types/49 HTTP/1.1
User-Agent: python-requests/2.25.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Cookie: mojolicious=...
Content-Length: 81
Content-Type: application/json
{"name": "BIND", "useInTable": "server", "description": "an updated description"}
```
```http
HTTP/1.1 400 Bad Request
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Content-Type: application/json
Permissions-Policy: interest-cohort=()
Set-Cookie: mojolicious=...; Path=/; Expires=Wed, 04 Aug 2021 15:54:23 GMT; Max-Age=3600; HttpOnly
Vary: Accept-Encoding
Whole-Content-Sha512: ...
X-Server-Name: traffic_ops_golang/
Date: Wed, 04 Aug 2021 14:55:24 GMT
Content-Length: 84
{
"alerts": [
{
"text": "can not update type",
"level": "error"
}
]
}
```
... and the only log line in the Traffic Ops logs that is output related to this request is an INFO-level log:
```
INFO: routing.go:247: 2021-08-04T14:54:23.423748804Z: PUT /api/3.0/types/49? handling (reqid 1746)
```
so the timeout was silently ignored.
Additionally, attempting to modify non-existent types returns a generic 400 Bad Request error code:
```shell
$ # gets the highest ID that currently exists
$ toget -kp types | jq '.response[]|.id' | sort -n | tail -n1
50
```
request (using `todelete -fkp types/51`):
```http
DELETE /api/3.0/types/51 HTTP/1.1
User-Agent: python-requests/2.25.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Cookie: mojolicious=...
Content-Length: 0
```
response:
```http
HTTP/1.1 400 Bad Request
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Content-Type: application/json
Permissions-Policy: interest-cohort=()
Set-Cookie: mojolicious=...; Path=/; Expires=Wed, 04 Aug 2021 13:59:13 GMT; Max-Age=3600; HttpOnly
Vary: Accept-Encoding
Whole-Content-Sha512: ...
X-Server-Name: traffic_ops_golang/
Date: Wed, 04 Aug 2021 12:59:13 GMT
Content-Length: 83
{
"alerts": [
{
"text": "can not delete type",
"level": "error"
}
]
}
```
This isn't enough information for the client to determine how to make their request succeed.
Finally, making requests that do fail for no more specific a reason than the request being "bad" in some way don't return enough information for a client to determine what was wrong and how to fix it:
```http
POST /api/3.0/types HTTP/1.1
User-Agent: python-requests/2.25.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Cookie: mojolicious=...
Content-Length: 77
Content-Type: application/json
{"name": "test", "useInTable": "anything but server", "description": "quest"}
```
response:
```http
HTTP/1.1 400 Bad Request
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Content-Type: application/json
Permissions-Policy: interest-cohort=()
Set-Cookie: mojolicious=...; Path=/; Expires=Wed, 04 Aug 2021 13:59:40 GMT; Max-Age=3600; HttpOnly
Vary: Accept-Encoding
Whole-Content-Sha512: ...
X-Server-Name: traffic_ops_golang/
Date: Wed, 04 Aug 2021 12:59:40 GMT
Content-Length: 83
{
"alerts": [
{
"text": "can not create type",
"level": "error"
}
]
}
```
... in this case the request failed because creating a Type with a "Use In Table" value other than exactly `"server"` is not allowed, which is not indicated in the response.
## Expected behavior:
Errors that occur internally as a result of conditions beyond the client's control should result in a 500 Internal Server error with something helpful placed in the logs for system administrators to look at to help diagnose and solve the problem. Errors that occur as a result of an invalid or malformed client request should return the appropriate status code in the range [400,500) with enough information in the Alerts to allow a client to fix their request so that it succeeds.
## Minimal reproduction of the problem with instructions:
For database timeout, I added a `time.Sleep(61*time.Secord)` to the `/types` function `AllowMutation` under the `if !forCreation {` line to force a timeout at that point (note that the db timeout is one day if you're using debug RPMs and set `TO_DEBUG=true` in `variables.env`, so that won't work without changes), and changed all of the timeouts inserted into Traffic Ops's configuration in `infrastructure/cdn-in-a-box/traffic_ops/config.sh` that weren't database-related (and I didn't change the proxy timeouts) to `120` so that nothing else would timeout, and started CiaB. Then, I stopped all CDN-in-a-Box services besides `trafficops`, `trafficvault`, `db`, and `dns` to get a clean view of the logs. For the other problems, the requests shown should reproduce the responses shown.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org