Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid character 'm' looking for beginning of value #424

Open
bgins opened this issue Nov 1, 2024 · 0 comments
Open

Invalid character 'm' looking for beginning of value #424

bgins opened this issue Nov 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@bgins
Copy link
Contributor

bgins commented Nov 1, 2024

While investigating our error handling, I uncovered an issue reporting HTTPErrors in response to posts to the solver.

Our HTTPError is defined here:

type HTTPError struct {
Message string
StatusCode int
}

It's a wrapper around an error message that let's us add a status code.

When handling a POST, a handler may return an HTTPError or a plain error:

lilypad/pkg/http/utils.go

Lines 246 to 257 in d30b6d8

data, err := handler(requestBody, res, req)
if err != nil {
log.Error().
Str("method POST", req.URL.String()).
Err(err).
Msgf("")
httpError, ok := err.(HTTPError)
if ok {
http.Error(res, httpError.Error(), httpError.StatusCode)
} else {
http.Error(res, err.Error(), http.StatusInternalServerError)
}

When using an HTTPError, we take the provided status code or otherwise report a 500 http.StatusInternalServerError status code.

The set up for triggering this error is a bit contrived, but likely reveals an underlying issue where we will fail to correctly report errors.

Start the chain and solver. Comment out the line of code where we add a user header in our clients:

req.Header.Add(X_LILYPAD_USER_HEADER, userPayload)

Start a resource provider. It should immediately fail with this error:

Error: invalid character 'm' looking for beginning of value

We handle this error when we check for the user header in the solver:

lilypad/pkg/http/utils.go

Lines 118 to 124 in d30b6d8

userHeader := req.Header.Get(X_LILYPAD_USER_HEADER)
if userHeader == "" {
return "", HTTPError{
Message: "missing user header",
StatusCode: http.StatusUnauthorized,
}
}

Stop the solver. Change the status code in the user header check to http.StatusInternalServerError.

Run the resource provider again and it will not fail with the invalid character error. Instead, it will retry attempts to contact the solver and eventually fail when the max retries are reached.

You may also want to reduce the number of retries to speed up the process:

retryClient.RetryMax = 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants