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

Don't try to parse body if HTTP status is not 200 #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VladRassokhin
Copy link

Improves error message from http response error: 401 - invalid content type into http unexpected status: 401 Unauthorized

Also unifies imports, code reuse.

@VladRassokhin VladRassokhin force-pushed the http-unexpected-status-error branch 3 times, most recently from bb74298 to 803af85 Compare April 27, 2018 20:21
@VladRassokhin
Copy link
Author

VladRassokhin commented Apr 27, 2018

Not sure yet seems that test WinRMSuite.TestOperationTimeoutSupport never worked as expected, I mean old code with replacing response body in case of non 200 code never worked because it was located after body parsing.

@VladRassokhin VladRassokhin force-pushed the http-unexpected-status-error branch from 803af85 to 9f69534 Compare April 27, 2018 20:23
@VladRassokhin
Copy link
Author

Removing w.WriteHeader(500) from command_test.go:234 fixes test.

@VladRassokhin
Copy link
Author

@masterzen Could you please take a look?

Copy link
Owner

@masterzen masterzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay in looking at your PR, and thanks for sending it.

I understand what you're trying to fix here, but unfortunately the proposed change breaks the fundamental feature of supporting transient Operation Timeout server errors (which are just to tell the client that the command hasn't produced any output in the given time), which are usually just ignored and retried.

I'm all in favor of DRYing the code base by reusing ParseSoapResponse as you did, but for the moment, leave the the forked azure-sdk-for-go imports until I've made clear that we're not supporting older Go environments (since this is a library this has the potential of breaking upstream things).

Would you mind amending your PR so that we still support the Operation Timeout error, but still report straight http errors?

Many thanks,
Brice

"strings"
"time"

"github.com/masterzen/azure-sdk-for-go/core/http"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this means we're breaking the compatibility with Go < 1.8.
But maybe we don't care anymore nowadays...

body, err := body(resp)
// error in case of incorrect exit code
if resp.StatusCode != 200 {
return "", fmt.Errorf("http unexpected status: %s", resp.Status)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if you get an operation timeout (which is also an HTTP 500 error), you'll return an error here that the upper layer will not "ignore" anymore (see command.go:134 and you'll break long running commands.

Note that OperationTimeout are SOAP errors, so they need to be parsed.
That's the reason your code breaks the TestOperationTimeoutSupport test (the test is designed to show that getting a timeout doesn't mean the command is aborted, it still runs on the server until there are more output to display).

So, I think we first have to check if the body is a soap+xml, then error as before, but we also have to carry over correctly the error message if it is a straight http error (and not a soap+xml error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants