Coder Social home page Coder Social logo

Good queries failing with "Response decode error" when running multiple requests in parallel via Amp\any - Fine when running in series about dns HOT 9 CLOSED

amphp avatar amphp commented on June 2, 2024
Good queries failing with "Response decode error" when running multiple requests in parallel via Amp\any - Fine when running in series

from dns.

Comments (9)

Daniel15 avatar Daniel15 commented on June 2, 2024

Okay so what I think is happening here is that it's mixing the responses, and valid queries are somehow getting the error responses. Some of the responses are actually erroneous. If you run the requests in series by replacing the for loop with:

  for (
    $current_ip_raw = $start_ip_raw - IPS_TO_LOAD;
    $current_ip_raw < $start_ip_raw + IPS_TO_LOAD;
    $current_ip_raw++
  ) {
    $current_ip = long2ip($current_ip_raw);
    $ips[] = $current_ip;
    try {
      $succeeded[$current_ip] = (yield Amp\Dns\query($current_ip, Amp\Dns\Record::PTR));
    } catch (Exception $ex) {
      $failed[$current_ip] = $ex;
    }
  }

and removing the list($failed, $succeeded) = (yield Amp\any($lookups)); line, you'll see that one request constantly fails. If you change IPS_TO_LOAD to 10, you'll see two requests consistently fail (209.141.56.28 and 209.141.56.35). However, when running these requests in parallel via Amp\any, other requests also fail.

from dns.

kelunik avatar kelunik commented on June 2, 2024

This is still an issue in the Amp v2 version, additionally we leak the exception there.

<?php

use Amp\Loop;

require __DIR__ . '/vendor/autoload.php';

function format_exception(Exception $ex, $indent = 0) {
    $output = get_class($ex) . ' - ' . $ex->getMessage();
    if ($ex instanceof Amp\CombinatorException) {
        foreach ($ex->getExceptions() as $inner) {
            $output .= "\n" . str_repeat('  ', $indent) . ' --> ' . format_exception($inner, $indent + 1);
        }
    } else {
        $prev = $ex->getPrevious();
        if ($prev) {
            $output .= "\n" . str_repeat('  ', $indent) . ' --> ' . format_exception($prev, $indent + 1);
        }
    }
    return $output;
}

const IPS_TO_LOAD = 2;

Loop::run(function () {
    $start_ip = '209.141.56.29';
    $start_ip_raw = ip2long($start_ip);

    for (
        $current_ip_raw = $start_ip_raw - IPS_TO_LOAD;
        $current_ip_raw < $start_ip_raw + IPS_TO_LOAD;
        $current_ip_raw++
    ) {
        $current_ip = long2ip($current_ip_raw);
        $ips[] = $current_ip;
        $lookups[$current_ip] = Amp\Dns\query($current_ip, Amp\Dns\Record::PTR);
    }

    list($failed, $succeeded) = (yield Amp\Promise\any($lookups));
    echo '**** ', count($failed), " failures! ****\n\n";
    foreach ($ips as $ip) {
        if (array_key_exists($ip, $succeeded)) {
            $result = $succeeded[$ip][0]->getValue();
            echo $ip, ': ', $result, "\n";
        } else if (array_key_exists($ip, $failed)) {
            $ex = $failed[$ip];
            if ($ex instanceof Amp\Dns\NoRecordException) {
                echo $ip, ": No reverse DNS\n";
            } else {
                echo $ip, ': EXCEPTION: ', format_exception($ex), "\n";
            }
        } else {
            echo $ip, ": UNKNOWN\n";
        }
    }
});

from dns.

kelunik avatar kelunik commented on June 2, 2024

Okay so what I think is happening here is that it's mixing the responses, and valid queries are somehow getting the error responses. Some of the responses are actually erroneous.

This is nothing caused by our library, it's the server responding with an empty domain name.

from dns.

bwoebi avatar bwoebi commented on June 2, 2024

I see no problems in the server response.
The failure is here or within libdns - I'm looking.

from dns.

kelunik avatar kelunik commented on June 2, 2024

@bwoebi It's in LibDNS.

from dns.

kelunik avatar kelunik commented on June 2, 2024

@bwoebi Seems like empty entries are indeed disallowed.

from dns.

kelunik avatar kelunik commented on June 2, 2024

Don't remember in which RFC I read that they're disallowed, can't find it again.

@DaveRandom ping.

from dns.

kelunik avatar kelunik commented on June 2, 2024

You sometimes get empty results now, but no more decode exceptions.

from dns.

DaveRandom avatar DaveRandom commented on June 2, 2024

LibDNS is being majorly refactored, one of the things that it will do is cease to validate things like this - i.e. context-dependent things (a domain name consisting of only the empty top-level label is, I suppose, theoretically valid).

In a case like this, however, I think it still makes sense for an exception to be throw by amp/dns (i.e. the client implementation). An empty domain name in response to a PTR query definitely does not make sense and is exceptional, even if it is dependent on external data.

One could perhaps have this behaviour controlled by an option to convert the response into the same behaviour as "non-existent record" when talking to buggy servers, but the default behaviour should be to throw. IMHO.

from dns.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.