Skip to content

fix(dispatcher): pass socketPath to custom connect callbacks#4857

Open
theamodhshetty wants to merge 2 commits intonodejs:mainfrom
theamodhshetty:codex/fix-socketpath-custom-connect
Open

fix(dispatcher): pass socketPath to custom connect callbacks#4857
theamodhshetty wants to merge 2 commits intonodejs:mainfrom
theamodhshetty:codex/fix-socketpath-custom-connect

Conversation

@theamodhshetty
Copy link
Contributor

Summary

When Pool / RoundRobinPool are created with a custom connect function, socketPath from dispatcher options is currently not forwarded to the connector callback options.

This patch fixes that by:

  • preserving socketPath in pool options passed down to Client
  • forwarding socketPath in Client connector invocation options when present
  • updating buildConnector.Options typing to include optional socketPath
  • adding regression tests for both Pool and RoundRobinPool

Fixes #3486.

Testing

  • node --test test/pool.js --test-name-pattern "passes socketPath to custom connect function"
  • node --test test/round-robin-pool.js --test-name-pattern "passes socketPath to custom connect function"
  • npx tsd --files test/types/connector.test-d.ts
  • npx eslint lib/core/symbols.js lib/dispatcher/client.js lib/dispatcher/pool.js lib/dispatcher/round-robin-pool.js test/pool.js test/round-robin-pool.js

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

the implementation lgtm, but unsure about the usage of a symbol and embedding the path into the client instance

this[kKeepAliveTimeoutValue] = this[kKeepAliveDefaultTimeout]
this[kServerName] = null
this[kLocalAddress] = localAddress != null ? localAddress : null
this[kSocketPath] = socketPath != null ? socketPath : null
Copy link
Member

Choose a reason for hiding this comment

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

any reason of why this is needed?

@theamodhshetty
Copy link
Contributor Author

Good callout, thanks. I pushed a follow-up to remove the symbol/client-instance storage approach.

What I changed:

  • no kSocketPath usage in Client anymore
  • when connect is a custom function and socketPath is provided, Client now wraps the custom connector and injects socketPath into connector opts
  • connect() now only passes runtime connection fields (host/port/localAddress/etc.)
  • added coverage in test/client.js for socketPath + custom connect

Commit: 32047692

kBodyTimeout: Symbol('body timeout'),
kServerName: Symbol('server name'),
kLocalAddress: Symbol('local address'),
kSocketPath: Symbol('socket path'),
Copy link
Member

Choose a reason for hiding this comment

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

remove?

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.15%. Comparing base (0bf0a2a) to head (3204769).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4857   +/-   ##
=======================================
  Coverage   93.14%   93.15%           
=======================================
  Files         109      109           
  Lines       34239    34243    +4     
=======================================
+ Hits        31893    31899    +6     
+ Misses       2346     2344    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm without the symbol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

socketPath option is not passed to the connect function

4 participants