dredd icon indicating copy to clipboard operation
dredd copied to clipboard

Dredd hooks time out sporadically

Open driesvints opened this issue 9 years ago • 28 comments

Describe your problem

We've been experiencing this problem for quite a while now. Dredd hooks sporadically time out for no apparent reason. We've set the --hooks-worker-connect-timeout flag to a very large value but with no luck. This happens on our CI build on CircleCI.

Here's the full log of a failed build.

cd ./api && /opt/circleci/nodejs/v7.5.0/bin/yarn run private
yarn run v0.19.1
$ yarn build && dredd build/private.apib http://0.0.0.0:3000/api --server="env APP_ENV=testing DB_DATABASE=beatswitchtest php ../artisan serve -q --host 0.0.0.0 --port 3000 --env testing" --language="../vendor/bin/dredd-hooks-php" --hookfiles="hooks/private/hooks.php" --hooks-worker-handler-host="0.0.0.0" --hooks-worker-connect-timeout="300000" --reporter="apiary" --reporter="dot" 
yarn build v0.21.3
$ hercule spec/public/intro.apib -o build/public.apib && hercule spec/private/intro.apib -o build/private.apib 
Done in 0.92s.
info: Starting backend server process with command: env APP_ENV=testing DB_DATABASE=beatswitchtest php ../artisan serve -q --host 0.0.0.0 --port 3000 --env testing
info: Waiting 3 seconds for backend server process to start
warn: Parser warning in file 'build/private.apib': (warning code 6) empty request message-body on line 87
info: Beginning Dredd testing...
info: Found Hookfiles: 0=hooks/private/hooks.php
info: Spawning '../vendor/bin/dredd-hooks-php' hooks handler process.
info: Hooks handler stdout: Starting server

info: Successfully connected to hooks handler. Waiting 0.1s to start testing.
.....warn: Hook handling timed out.
warn: Hook handling timed out.
F......
info: Displaying failed tests...
fail: DELETE /events/2/artist-types/2 duration: 5002ms
fail: Failed in before hook: Hook timed out.
request: 


expected: 


actual: 




complete: 11 passing, 1 failing, 0 errors, 0 skipped
complete: Tests took 34641ms
complete: See results in Apiary at: [redacted]
info: Backend server process exited
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

cd ./api && /opt/circleci/nodejs/v7.5.0/bin/yarn run private returned exit code 1

As I said, this happens sporadically and not to a specific test. It can happen to multiple tests or a single one. Succeeds more than it fails but doesn't matters if code has changed or not.

What command line options do you use?

$ dredd build/private.apib http://0.0.0.0:3000/api --server="env APP_ENV=testing DB_DATABASE=beatswitchtest php ../artisan serve -q --host 0.0.0.0 --port 3000 --env testing" --language="../vendor/bin/dredd-hooks-php" --hookfiles="hooks/private/hooks.php" --hooks-worker-handler-host="0.0.0.0" --hooks-worker-connect-timeout="300000" --reporter="apiary" --reporter="dot" 

What's your dredd --version output?

This is on the Vagrant machine. I'm not sure what the output on the CI build would be. The version should be the same.

dredd v3.5.1 (Linux 4.4.0-83-generic; x64)

Does dredd --level=debug uncover something?

I tried to run with this flag but couldn't immediately tell something from it. I haven't triggered a failing build with this flag yet.

driesvints avatar Jul 11 '17 10:07 driesvints

Thanks for the report! We need to figure out where exactly the thing hangs. Please, try out running Dredd in all your CI builds with --level=debug or even better, with --level=silly. When you experience the hang again, copy-paste the output here, please. It will be clearer whether it's a network problem, hooks problem, Dredd problem, ...

honzajavorek avatar Jul 11 '17 12:07 honzajavorek

Heya. Any update on this? It's really giving us a headache. Builds fail randomly.

driesvints avatar Jul 19 '17 19:07 driesvints

@driesvints Not yet, unfortunately. I'll try to prioritize this when I'm back in work on Mon.

honzajavorek avatar Jul 20 '17 10:07 honzajavorek

@honzajavorek Thank you! :)

driesvints avatar Jul 20 '17 10:07 driesvints

So with the most verbose logging turned on, the output looks like this:

verbose: Running 'beforeEach' hooks
debug: Running hooks...
verbose: Sending HTTP transaction data to hooks handler: uuid...
warn: Hook handling timed out.

According to @driesvints' Dredd output I have access to, for a single transaction it's possible for multiple hook calls to timeout, while other pass correctly. E.g. beforeEach and afterEach times out, but before and after execute correctly.

My hunch is this is probably something with PHP hooks (cc @ddelnano). Unless we prove this can be reproduced with other hook handlers, I consider this bug to be PHP-specific.

@driesvints What version of PHP hooks do you have? How does your dredd.yml look like? Did you update the PHP hooks recently? Also, are you able to track down at which moment this started to occur in your builds?

One more idea - the only recent change affecting hook handlers was https://github.com/apiaryio/dredd/pull/803, released as v4.1.0. Could you try downgrading Dredd for a while to test whether it fixes the problem?

honzajavorek avatar Jul 25 '17 11:07 honzajavorek

@honzajavorek heya, thanks for looking into this!

I'm using the latest version of the hooks: 1.1.5.

I don't have a dredd.yml. I have two scripts defined in my package.json because I need to test to a public and a private specification. That looks like this:

  "scripts": {
    "build": "hercule spec/public/intro.apib -o build/public.apib && hercule spec/private/intro.apib -o build/private.apib",
    "public": "yarn build && dredd build/public.apib http://0.0.0.0:3000/api/public --server=\"env APP_ENV=testing DB_DATABASE=beatswitchtest php ../artisan serve -q --host 0.0.0.0 --port 3000 --env testing\" --language=\"../vendor/bin/dredd-hooks-php\" --hookfiles=\"hooks/public/hooks.php\" --hooks-worker-handler-host=\"0.0.0.0\" --hooks-worker-connect-timeout=\"300000\" --reporter=\"apiary\" --reporter=\"dot\"",
    "private": "yarn build && dredd build/private.apib http://0.0.0.0:3000/api --server=\"env APP_ENV=testing DB_DATABASE=beatswitchtest php ../artisan serve -q --host 0.0.0.0 --port 3000 --env testing\" --language=\"../vendor/bin/dredd-hooks-php\" --hookfiles=\"hooks/private/hooks.php\" --hooks-worker-handler-host=\"0.0.0.0\" --hooks-worker-connect-timeout=\"300000\" --reporter=\"apiary\" --reporter=\"dot\""
  }

Cumbersome I know but I can't use the same dredd.yml for each. I have all of the api stuff in an api/ subdirectory, that's why you see the ../ references.

I didn't change the hooks recently. It's hard to track this down. We run hundreds of builds each week. I'd say the timeouts have always happened in some form. We always updated the timeout for them but it doesn't seems to solve the issues anymore now.

I've updated Dredd to the latest version (4.1.2) about a week ago but it didn't solve the problems. Why downgrading? Did you mean upgrading? We're running v3.5.1 now on master (see issue description).

driesvints avatar Jul 27 '17 12:07 driesvints

I can't use the same dredd.yml for each

BTW, you could use --config (docs, example).

Why downgrading?

Because in v4.1.0 there was a feature which could theoretically affect hooks. But since you're running v3.5.1 (which I did not notice previously, I'm sorry) it's irrelevant suggestion.

We need to factor out the root cause somehow. There're still way too many things in the mix and very little clues. I have one more idea, but let me check some things first.

honzajavorek avatar Jul 27 '17 12:07 honzajavorek

My idea would be that the brand new cross-platform subprocess implementation introduced in v3.4.0 could have an impact on how the hook handlers are being started and treated.

Do you think you could run couple of builds with Dredd v3.3.1 to see whether you experience the timeouts as well? Branch out from master, downgrade Dredd, then push to CI and retry 10+ times, to see how reliable it is compared to what you have in master.

honzajavorek avatar Jul 27 '17 12:07 honzajavorek

@driesvints Any updates on this? 👀

honzajavorek avatar Aug 15 '17 14:08 honzajavorek

Unfortunately not... work is keeping me from spending time on this and I'm on vacation this week. I'll try to see if they'll allow me to get back to this next week. Sorry about the delay but unfortunately out of my hands atm. 😕

driesvints avatar Aug 15 '17 17:08 driesvints

I've got some time this week to work on this.

BTW, you could use --config

TIL 😀

Do you think you could run couple of builds with Dredd v3.3.1 to see whether you experience the timeouts as well?

Yep, will try. I'll let you know the results.

driesvints avatar Aug 21 '17 13:08 driesvints

@honzajavorek unfortunately the problem persists with 3.3.1 😔

driesvints avatar Aug 23 '17 11:08 driesvints

Honestly, I'm quite out of ideas. It can be something specific to your environment, network, OS, or to PHP hooks. The fact it's flaky doesn't really help to debug it. I'm afraid without some digging on your side we can't do much to find the root cause 😞 I'll get back here if I come up with any new ideas what else could help.

honzajavorek avatar Aug 28 '17 11:08 honzajavorek

@driesvints it would be helpful to have a tcpdump when things are behaving both normally and abnormally

ddelnano avatar Aug 28 '17 12:08 ddelnano

@ddelnano how would I do such a tcpdump?

driesvints avatar Aug 31 '17 14:08 driesvints

@driesvints while running the dredd tests you need to capture packets using the following command.

sudo tcpdump -i lo0 -w capture.pcap -Xnnvvs0 port 61321

Before attempting the saving of it though you should make sure you see traffic by omitting some of those flags.

sudo tcpdump -i lo0 port 61321

Make sure you see something like this before running the first command.

screen shot 2017-09-01 at 6 33 03 pm

If you send me pcap files that captures one timeout and one success test run I'd be happy to take a look ([email protected]).

ddelnano avatar Sep 01 '17 22:09 ddelnano

@ddelnano getting this back when I try to run it (sorry real noob here)

tcpdump: lo0: No such device exists
(SIOCGIFHWADDR: No such device)

driesvints avatar Sep 06 '17 12:09 driesvints

@driesvints well that is definitely not expected haha. What does ifconfig show looks like you don't have a loopback interface.

ddelnano avatar Sep 06 '17 12:09 ddelnano

@driesvints oops sorry I realized you are doing this on Circle CI. Unfortunately I don't think you will be able to tcpdump on a cloud based ci platform. Are you able to reproduce this on a host you have access to?

ddelnano avatar Sep 06 '17 12:09 ddelnano

@ddelnano it's only specifically happening on CircleCI

driesvints avatar Sep 06 '17 12:09 driesvints