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

Consistent failure of test-http-client-timeout-option-with-agent #25746

Closed
devsnek opened this issue Jan 27, 2019 · 13 comments
Closed

Consistent failure of test-http-client-timeout-option-with-agent #25746

devsnek opened this issue Jan 27, 2019 · 13 comments
Labels
flaky-test Issues and PRs related to the tests with unstable failures on the CI. http Issues or PRs related to the http subsystem. test Issues and PRs related to the tests.

Comments

@devsnek
Copy link
Member

devsnek commented Jan 27, 2019

Every time I run the suite I see this failure:

=== release test-http-client-timeout-option-with-agent ===
Path: parallel/test-http-client-timeout-option-with-agent
assert.js:351
    throw err;
    ^

AssertionError [ERR_ASSERTION]: duration 2992ms less than timeout 3000ms
    at ClientRequest.req.on.common.mustCall (node/test/parallel/test-http-client-timeout-option-with-agent.js:46:12)
    at ClientRequest.<anonymous> (node/test/common/index.js:368:15)
    at ClientRequest.emit (events.js:197:13)
    at Socket.emitRequestTimeout (_http_client.js:666:40)
    at Object.onceWrapper (events.js:285:13)
    at Socket.emit (events.js:197:13)
    at Socket._onTimeout (net.js:422:8)
    at listOnTimeout (timers.js:324:15)
    at processTimers (timers.js:268:5)
Command: out/Release/node node/test/parallel/test-http-client-timeout-option-with-agent.js

cc @Trott who messed with the timers in this test last

@devsnek devsnek added http Issues or PRs related to the http subsystem. test Issues and PRs related to the tests. flaky-test Issues and PRs related to the tests with unstable failures on the CI. labels Jan 27, 2019
@Trott
Copy link
Member

Trott commented Jan 27, 2019

Do you see the failure when you run tools/test.py test/parallel/test-http-client-timeout-option-with-agent.js or only when you run make test or what exactly?

@Trott
Copy link
Member

Trott commented Jan 27, 2019

Seems to me like maybe const start = Date.now(); should be moved immediately before const req = http.request(options); instead of coming immediately after it? If that seems about right to you, does that change fix things for you?

@devsnek
Copy link
Member Author

devsnek commented Jan 27, 2019

@Trott it goes from 2993ms to 2998ms, so definitely closer, but still not passing.

@Trott
Copy link
Member

Trott commented Jan 27, 2019

What happens with this one (which also switches to process.hrtime.bigint())?:

'use strict';
const common = require('../common');

// Test that when http request uses both timeout and agent,
// timeout will work as expected.

const assert = require('assert');
const http = require('http');

const HTTP_AGENT_TIMEOUT = 1000;
const HTTP_CLIENT_TIMEOUT = 3000;

const agent = new http.Agent({ timeout: HTTP_AGENT_TIMEOUT });
const options = {
  method: 'GET',
  port: undefined,
  host: '127.0.0.1',
  path: '/',
  timeout: HTTP_CLIENT_TIMEOUT,
  agent,
};

const server = http.createServer(() => {
  // Never respond.
});

server.listen(0, options.host, () => {
  doRequest();
});

function doRequest() {
  options.port = server.address().port;
  const start = process.hrtime.bigint();
  const req = http.request(options);
  req.on('error', () => {
    // This space is intentionally left blank.
  });
  req.on('close', common.mustCall(() => server.close()));

  let timeout_events = 0;
  req.on('timeout', common.mustCall(() => {
    timeout_events += 1;
    const duration = process.hrtime.bigint() - start;
    // The timeout event cannot be precisely timed. It will delay
    // some number of milliseconds.
    assert.ok(
      duration >= BigInt(HTTP_CLIENT_TIMEOUT * 1e6),
      `duration ${duration}ms less than timeout ${HTTP_CLIENT_TIMEOUT}ms`
    );
  }));
  req.end();

  setTimeout(() => {
    req.destroy();
    assert.strictEqual(timeout_events, 1);
    // Ensure the `timeout` event fired only once.
  }, common.platformTimeout(HTTP_CLIENT_TIMEOUT * 2));
}

I'll be mildly surprised if that actually fixes it for you, but if so, hey, great.

@Trott
Copy link
Member

Trott commented Jan 27, 2019

Another thing to try might be to see if the test passes if you set the agent timeout constant to 3000 instead of 1000. If the test starts passing then, that suggests that this may be a legitimate bug and not a problem with the test.

@devsnek
Copy link
Member Author

devsnek commented Jan 28, 2019

@Trott it passes with bigint, but it also passes when i change it to 1000ms

@Trott
Copy link
Member

Trott commented Jan 28, 2019

@nodejs/http

@Trott
Copy link
Member

Trott commented Jan 28, 2019

@devsnek What OS are you running?

@Trott
Copy link
Member

Trott commented Jan 28, 2019

I think switching to process.hrtime.bigint() is probably a good change anyway, so I'd be inclined to do that and call it good. Thoughts? @nodejs/testing

@devsnek
Copy link
Member Author

devsnek commented Jan 28, 2019

@Trott macos 10.14.3

Trott added a commit to Trott/io.js that referenced this issue Jan 28, 2019
* Switch from Date.now() to process.hrtime.bigint().
* Move start time recording to before the request is created, not after.

Fixes: nodejs#25746
@Trott
Copy link
Member

Trott commented Jan 28, 2019

That's Mojave, right? You didn't update very recently, did you?

@Trott
Copy link
Member

Trott commented Jan 28, 2019

PR to fix: #25752

Trott added a commit to Trott/io.js that referenced this issue Jan 30, 2019
* Switch from Date.now() to process.hrtime.bigint().
* Move start time recording to before the request is created, not after.

Fixes: nodejs#25746

PR-URL: nodejs#25752
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@Trott
Copy link
Member

Trott commented Jan 30, 2019

Fixed in b897704

@Trott Trott closed this as completed Jan 30, 2019
targos pushed a commit that referenced this issue Jan 30, 2019
* Switch from Date.now() to process.hrtime.bigint().
* Move start time recording to before the request is created, not after.

Fixes: #25746

PR-URL: #25752
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flaky-test Issues and PRs related to the tests with unstable failures on the CI. http Issues or PRs related to the http subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants