That code is incomplete and not runnable. What is "[0:netip]" for example? More importantly, what is "c" when you do c.Write(data) ?

However, there is also an unstated question here, which is "how are the requests and responses delimited when PowerDNS using the unixsock remote backend?"  You're just assuming that a Read() and a Write() are sufficient to delimit messages, and that seems pretty unlikely to me.

Now, looking in the Ruby code in modules/remotebackend/unittest_pipe.rb, it appears that the format is newline-delimited, i.e. this is JSON-Lines <https://jsonlines.org/>.

This appears to be confirmed in modules/remotebackend/pipeconnector.cc

int PipeConnector::send_message(const Json& input)
{
  auto line = input.dump();
  launch();

*  line.append(1, '\n');*

...

    if (!stringfgets(d_fp.get(), receive)) {
      throw PDNSException("Child closed pipe");
    }

// stringfgets is in pdns/misc.cc, and it reads up to a newline:

  do {
    if(!fgets(buffer, sizeof(buffer), fp))
      return !line.empty();

    line.append(buffer);
*  } while(!strchr(buffer, '\n'));*
  return true;

So the main issue seems to be: you need to write a newline after your JSON response.  (And make sure your response *isn't* pretty-printed, and any embedded newlines in strings are represented by "\n", so that each JSON object is exactly one line)

Then instead of Read(1024), you need to either read up to a newline (e.g. using bufio.Scanner or bufio.Reader) - or you need to use a streaming JSON decoder which will use the end of each JSON object as the delimiter, and ignores the newlines in between them.  (Go's encoding/json can quite happily do that)

HTH,

Brian.
_______________________________________________
Pdns-users mailing list
Pdns-users@mailman.powerdns.com
https://mailman.powerdns.com/mailman/listinfo/pdns-users

Reply via email to