Skip to content

cmd test flake: 0-length response instead of expected timeout - #15885

Merged
openshift-merge-robot merged 1 commit into
openshift:masterfrom
abstractj:issue-15453
Sep 6, 2017
Merged

openshift-merge-robot merged 1 commit into
openshift:masterfrom
abstractj:issue-15453

Conversation

@abstractj

Copy link
Copy Markdown

It looks like this issue is related with HEAD request that we do. By
changing it to send HTTP GET requests to our /healthz endpoint seems
to fix the issue.

Signed-off-by: Bruno Oliveira [email protected]

@juanvallejo @fabianofranz it seems to fix the issue #15453

@openshift-merge-robot openshift-merge-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 21, 2017
@abstractj

Copy link
Copy Markdown
Author

/assign @juanvallejo

@abstractj

Copy link
Copy Markdown
Author

/retest

1 similar comment
@abstractj

Copy link
Copy Markdown
Author

/retest

@@ -68,8 +68,8 @@ func dialToServer(clientConfig restclient.Config) error {

// Do a HEAD request to serverPathToDial to make sure the server is alive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment is now out of sync?


// Do a HEAD request to serverPathToDial to make sure the server is alive.
// We don't care about the response, any err != nil is valid for the sake of reachability.
serverURLToDial := (&url.URL{Scheme: parsedURL.Scheme, Host: parsedURL.Host, Path: "/"}).String()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does / vs /healthz matter?

Comment thread pkg/oc/cli/cmd/login/helpers.go Outdated
serverURLToDial := (&url.URL{Scheme: parsedURL.Scheme, Host: parsedURL.Host, Path: "/"}).String()
req, err := http.NewRequest("HEAD", serverURLToDial, nil)
serverURLToDial := (&url.URL{Scheme: parsedURL.Scheme, Host: parsedURL.Host, Path: "/healthz"}).String()
req, err := http.NewRequest("GET", serverURLToDial, nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I will defer to @openshift/cli-review to understand this.

@juanvallejo

Copy link
Copy Markdown
Contributor

@abstractj per our conversation, it looks like the most likely cause of the 0-length response error is a remote call made using the kube rest client. Headers are received, but looks like the connection is timed out before the body is received, resulting in no actual connection error (or even an error from the server), but an error from the request response handler.

@fabianofranz I am not sure what the best solution would be here; one thing we could consider is looking for both outcomes in the test (0-length response and Client.Timeout exceeded...). We could also replace the test altogether, such that it doesn't depend on the connection timing out before headers are received.

@abstractj

abstractj commented Aug 23, 2017 •

Copy link
Copy Markdown
Author

@juanvallejo the first alternative to me seems like a simple fix. The second suggestion of replacing the test, I'm not sure if I follow. If we are not going to depend on the connection timing out, it feels like timeout.sh will lose it's purpose. Am I wrong?

If the idea is to increase the timeout to 500ms or 1s, like you mentioned on IRC, I tried that too, but at least locally here I get a crash at kube/config:

error: A server URL must be specified
error: yaml: line 31: could not find expected ':'
error: yaml: line 17: could not find expected ':'
error: yaml: line 29: could not find expected ':'
error: yaml: line 11: could not find expected ':'
error: yaml: line 19: could not find expected ':'

Maybe is my setup, but it only happens if I change it. If that's not happening to you, feel free to ignore.

Here's my testing script:

#!/bin/sh
rm -f log.txt
# Cleanup cluster resources created by this test
(
set +e
oc delete all,templates --all
exit 0
) &>/dev/null


oc new-app node

while true; do
   oc login -u testuser -p test --request-timeout=1s 2>> log.txt &
   if grep -q "error" "log.txt"; then
     echo "Error found...leaving"
     exit 1
   fi
done

@juanvallejo

juanvallejo commented Aug 23, 2017 •

Copy link
Copy Markdown
Contributor

@abstractj

The second suggestion of replacing the test, I'm not sure if I follow. If we are not going to depend on the connection timing out, it feels like timeout.sh will lose it's purpose. Am I wrong?

We are still testing for connection timeout in at least one other test in timeout.sh. The only difference is that the linked case is not racing against the connection timing out before headers are received from the server in order to succeed, which is what oc login ... --request-timeout=1ns is doing.

If the idea is to increase the timeout to 500ms or 1s, like you mentioned on IRC, I tried that too, but at least locally here I get a crash at kube/config

Seems like your kubeconfig file is getting corrupted; since you're putting each call to oc... in the background every loop iteration, maybe you're ending up doing multiple calls to oc login before the last call has had a chance to finish editing your kubeconfig file. Related BZ.

Here is a patch for oc login that should help you replicate the 0-length response error by looping over the rest call to /oapi/v1/users/~ directly.

@abstractj

Copy link
Copy Markdown
Author

@fabianofranz I was chatting with @juanvallejo on IRC on yesterday and we have some options to fix this issue:

  1. Use the /healthz endpoint with GET like suggested in this PR. That would fix the issue, but at the same, we don't know really why. Which is really bad.

  2. Replace the line with oc login by something like oc get pods --watch --request-timeout=1s. Suggested by Juan.

IMO, option 2 is the best alternative. Because it seems like there's no other better (flake-free) alternative to keep oc login in that test.

Wdyt?

@fabianofranz

Copy link
Copy Markdown
Contributor

@abstractj @juanvallejo option 2 works for me.

@abstractj

Copy link
Copy Markdown
Author

@juanvallejo @fabianofranz cool, PR updated.

@abstractj

Copy link
Copy Markdown
Author

/retest

@abstractj

Copy link
Copy Markdown
Author

/retest

@juanvallejo

Copy link
Copy Markdown
Contributor

@abstractj

Copy link
Copy Markdown
Author

/retest

@abstractj

Copy link
Copy Markdown
Author

@juanvallejo I'm a bit confused about the testsuite. The reason why it fails is due to a wrong output. So if we replace that line with:

os::cmd::expect_failure_and_text "oc get pods --watch-only --request-timeout=1s 2>&1 | cut -d '.' -f4 | cut -d ')' -f1" 'Timeout exceeded while reading body'

Line 19 will fail, even if we get the correct output. But if instead we switch to something like:

os::cmd::expect_success_and_text "oc get pods --watch-only --request-timeout=1s 2>&1 | cut -d '.' -f4 | cut -d ')' -f1" 'Timeout exceeded while reading body'

All the tests will pass.

@juanvallejo

juanvallejo commented Aug 31, 2017 •

Copy link
Copy Markdown
Contributor

@abstractj hm, I think all you should need to do is redirect stderr to stdout and then expect_success_and_text. Doing oc get pods --watch with a request timeout exits with code 0, which explains why expecting a failure in the tests does not work:

$ oc get pods --watch --request-timeout 1s
NAME              READY     STATUS    RESTARTS   AGE
mypod             1/1       Running   0          38s
E0831 14:49:00.148260   11753 streamwatcher.go:109] Unable to decode an event from the watch stream: net/http: request canceled (Client.Timeout exceeded while reading body)

$ echo $?
0

@abstractj

Copy link
Copy Markdown
Author

@abstractj hm, I think all you should need to do is redirect stderr to stdout and then expect_success_and_text. Doing oc get pods --watch with a request timeout exits with code 0, which explains why expecting a failure in the tests does not work:

@juanvallejo I don't think that gonna work just redirecting stderr to stdout. Because as you can see below the error is there with more output. So if the testsuite look for Timeout exceeded while reading body it won't match. Because the output is E0831 14:49:00.148260 11753 streamwatcher.go:109] Unable to decode an event from the watch stream: net/http: request canceled (Client.Timeout exceeded while reading body)

With my latest changes using some cut, sed or awk is possible to filter such string. It does not sound beautiful, but that was the best I could come up.

$ oc get pods --watch --request-timeout 1s
NAME              READY     STATUS    RESTARTS   AGE
mypod             1/1       Running   0          38s
E0831 14:49:00.148260   11753 streamwatcher.go:109] Unable to decode an event from the watch stream: net/http: request canceled (Client.Timeout exceeded while reading body)

$ echo $?
0

I noticed that too. But due to my ignorance on the testsuite, I felt like I was doing something wrong.

@abstractj

Copy link
Copy Markdown
Author

@fabianofranz thank God, all green :)

@juanvallejo

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 5, 2017
@fabianofranz

Copy link
Copy Markdown
Contributor

/approve #15453
Thanks @abstractj!

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abstractj, fabianofranz, juanvallejo

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 6, 2017
@openshift-merge-robot

Copy link
Copy Markdown
Contributor

Automatic merge from submit-queue (batch tested with PRs 15885, 15973, 16000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants