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

net: Support lookup of one address in net.LookupFunction (autoSelectFamily: false) #68213

Merged

Conversation

lefebvree
Copy link
Contributor

@lefebvree lefebvree commented Jan 16, 2024

This PR updates the net.LookupFunction to accept lookup of a single address on Node 18+.

The net.LookupFunction was updated to only accept dns.LookupAllOptions options instead of dns.LookupOneOptions and a callback signature expecting an array of dns.LookupAddress:

options: dns.LookupAllOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void,

However even though the default autoSelectFamily was changed, the node implementation still supports the lookup of a single address with autoSelectFamily: false or globally with net.setDefaultAutoSelectFamily(false)

net.LookupFunction diverges from the dns.lookup one (which is typed to support both). This does not compile but should:

net.createConnection({
  autoSelectFamily: false, // expects callback with a single address
  port: 80,
  lookup: (hostname, options, callback) => {
    callback(null, '127.0.0.1', 4) // this should be accepted
  },
})
Node code to lookup a single address with `dns.lookup`
const net = require('net')
const dns = require('dns')

var socket = net.createConnection({
  host: 'google.com',
  port: 80,
  autoSelectFamily: false, // or net.setDefaultAutoSelectFamily(false)
  lookup: (hostname, options, callback) => {
    console.log('lookup options', options)
    dns.lookup(hostname, options, (...args) => {
      console.warn('lookup callback', args)
      callback(...args)
    })
  },
})
socket.on('connect', () => socket.write("GET / HTTP/1.0\r\n\r\n"))
lookup options { family: undefined, hints: 1024 } // ← all: true is not set
lookup callback [ null, '172.217.20.174', 4 ]     // ← callback with a single address and family

If changing an existing definition:

@typescript-bot typescript-bot added this to Needs Author Action in New Pull Request Status Board Jan 16, 2024
@lefebvree lefebvree marked this pull request as ready for review January 16, 2024 13:37
@lefebvree lefebvree changed the title net: Support lookup of one address in net.LookupFunction (all: false) net: Support lookup of one address in net.LookupFunction (autoSelectFamily: false) Jan 16, 2024
@typescript-bot
Copy link
Contributor

typescript-bot commented Jan 16, 2024

@lefebvree Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 68213,
  "author": "lefebvree",
  "headCommitOid": "9d23f07a7ec47f50719c04d9a1cc5ee620d6851c",
  "mergeBaseOid": "68a06dbd340bd1a6442f1d22d01ac071e7ec9dd1",
  "lastPushDate": "2024-01-16T13:03:06.000Z",
  "lastActivityDate": "2024-02-01T09:02:48.000Z",
  "maintainerBlessed": "Waiting for Code Reviews",
  "mergeOfferDate": "2024-01-31T18:41:28.000Z",
  "mergeRequestDate": "2024-02-01T09:02:48.000Z",
  "mergeRequestUser": "lefebvree",
  "hasMergeConflict": false,
  "isFirstContribution": true,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/net.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/test/http.ts",
          "kind": "test"
        },
        {
          "path": "types/node/test/https.ts",
          "kind": "test"
        },
        {
          "path": "types/node/test/net.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/net.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/ts4.8/test/http.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/test/https.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/test/net.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/net.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/test/net.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/ts4.8/net.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/ts4.8/test/net.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Microsoft",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "n-e",
        "galkin",
        "parambirs",
        "eps1lon",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "ZYSzys",
        "NodeJS",
        "LinusU",
        "wafuwafu13",
        "mcollina",
        "Semigradsky"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "peterblazejewicz",
      "date": "2024-01-31T19:11:27.000Z",
      "isMaintainer": true
    },
    {
      "type": "approved",
      "reviewer": "btoueg",
      "date": "2024-01-31T13:54:40.000Z",
      "isMaintainer": false
    },
    {
      "type": "approved",
      "reviewer": "chinthakagodawita",
      "date": "2024-01-24T06:43:47.000Z",
      "isMaintainer": false
    }
  ],
  "mainBotCommentID": 1893761751,
  "ciResult": "pass"
}

@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Jan 16, 2024
@Semigradsky
Copy link
Contributor

cc @chinthakagodawita

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Jan 16, 2024
Copy link
Contributor

@chinthakagodawita chinthakagodawita left a comment

Choose a reason for hiding this comment

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

Ouch, I hadn't considered the case where autoSelectFamily was explicitly disabled!

One question about Node 16, but otherwise this change looks good to me :)

Comment on lines 21 to 22
options: dns.LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this correct. From what I can see, "lookup multiple" only landed in Node 18+ with the advent of auto-select-family

Specifically Node 18.13:

For reference, this is the Node 16 code: https://github.com/nodejs/node/blob/76f9a7d27f5ae9852b9ffc67a7dec1af503e0813/lib/net.js#L1107-L1195

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, thanks for catching that! I assumed net.LookupFunction and dns.lookup needed to match but that's not the case prior to Node 18, I amended the commit to leave v16 as it was.

Update `net` LookupFunction to accept both `option.all` as truthy or
falsy, and return one address / family or an array of `LookupAddress`.
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Code Reviews in New Pull Request Status Board Jan 18, 2024
@typescript-bot
Copy link
Contributor

@chinthakagodawita Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Jan 18, 2024
Copy link
Contributor

@chinthakagodawita chinthakagodawita left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@typescript-bot typescript-bot added the Other Approved This PR was reviewed and signed-off by a community member. label Jan 24, 2024
@RyanCavanaugh RyanCavanaugh moved this from Needs Maintainer Review to Waiting for Code Reviews in New Pull Request Status Board Jan 25, 2024
@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label Jan 27, 2024
@typescript-bot
Copy link
Contributor

Copy link

@btoueg btoueg left a comment

Choose a reason for hiding this comment

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

LGTM

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Jan 31, 2024
@typescript-bot
Copy link
Contributor

@lefebvree: Everything looks good here. I am ready to merge this PR (at 9d23f07) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@microsoft, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @ZYSzys, @nodejs, @LinusU, @wafuwafu13, @mcollina, @Semigradsky: you can do this too.)

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Waiting for Author to Merge in New Pull Request Status Board Jan 31, 2024
@lefebvree
Copy link
Contributor Author

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Feb 1, 2024
@typescript-bot typescript-bot merged commit 7315318 into DefinitelyTyped:master Feb 1, 2024
3 checks passed
@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Feb 1, 2024
codershiba pushed a commit to codershiba/DefinitelyTyped that referenced this pull request Feb 3, 2024
…n `net.LookupFunction` (`autoSelectFamily: false`) by @lefebvree

Update `net` LookupFunction to accept both `option.all` as truthy or
falsy, and return one address / family or an array of `LookupAddress`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical package Maintainer Approved Other Approved This PR was reviewed and signed-off by a community member. Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants