Support custom socket address resolution - #392
Merged
Merged
Conversation
affonsov
force-pushed
the
affonsov/address-resolver
branch
from
May 12, 2026 01:08
a426541 to
6ba751a
Compare
Port PRs valkey-io/valkey-glide#5328, #5876, #5890, #5891 to the C# client. Adds an optional AddressResolverDelegate callback to the connection configuration that intercepts and rewrites server host/port pairs before the client establishes connections. Useful for routing through proxies or custom DNS resolution. Implementation follows the direct FFI callback pattern (same as Go), not the socket listener/registry pattern used by Python and Node. Changes: - Update valkey-glide submodule to b4b34a1dc16d (includes core Rust infra from #5328 and FFI layer from #5876) - rust/src/ffi.rs: add address_resolver: None to ConnectionRequest - rust/src/lib.rs: add AddressResolverCallback type, FFIAddressResolver struct implementing redis::AddressResolver, update create_client with optional 5th address_resolver parameter - FFI.methods.cs: add 5th IntPtr addressResolverCallback param to both CreateClientFfi declarations - ConnectionConfiguration.cs: add AddressResolverDelegate public delegate, AddressResolver field, WithAddressResolver() builder method - BaseClient.cs: add AddressResolverAction delegate, _addressResolverDelegate field (GC-safe), wire up in CreateClient<T> - AddressResolverTests.cs: 5 unit tests Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
affonsov
force-pushed
the
affonsov/address-resolver
branch
from
May 12, 2026 01:51
6ba751a to
2ff8a4b
Compare
currantw
reviewed
May 12, 2026
currantw
reviewed
May 12, 2026
currantw
reviewed
May 12, 2026
currantw
reviewed
May 12, 2026
currantw
reviewed
May 12, 2026
… into affonsov/address-resolver Signed-off-by: currantw <taylor.curran@improving.com>
…callback, and refactor adddress resolver tests Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
- Wrap user-provided AddressResolver delegate in try/catch to prevent process crash if the delegate throws an exception - Log the exception at Error level for debuggability - Return 0 to signal failure to Rust, which falls back to the original address (consistent with Java client behavior) - Add integration test verifying fallback behavior when resolver throws Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
…g integration tests. Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Rust: - Extract MAX_RESOLVED_HOST_LEN constant (1024 bytes) - Use stack allocation instead of heap for resolve buffer - Add full doc comments on AddressResolverCallback matching SuccessCallback/FailureCallback style - Add doc comment on FFIAddressResolver explaining newtype pattern - Add SAFETY comment on unsafe impl Send + Sync - Document fallback behavior on resolve() method - Add address_resolver to create_client safety docs C#: - Expand AddressResolverDelegate XML docs (use cases, thread safety, error behavior, reconnection note) - Add <seealso> tag on AddressResolver property - Extract addressResolver local variable to avoid capturing config.Request - Add comment on unsafe pointer write (outLen always valid from Rust) - Add comment explaining why _addressResolverDelegate is not readonly - Log specific error messages for each failure case (empty host, oversized host, invalid port) Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
… into affonsov/address-resolver
alexr-bq
approved these changes
May 26, 2026
5 tasks
xShinnRyuu
approved these changes
May 26, 2026
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
… into affonsov/address-resolver
This was referenced Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the custom socket address resolution feature from valkey-glide to the C# client. Allows users to provide a callback that intercepts and rewrites server host/port pairs before the client establishes connections - useful for routing through proxies or custom DNS resolution.
Issue Link
This pull request is linked to issue: N/A (porting from upstream valkey-glide)
Features and Behaviour Changes
AddressResolverDelegateinConnectionConfiguration:WithAddressResolver()builder method on bothStandaloneClientConfigurationBuilderandClusterClientConfigurationBuildernullby default, no behaviour change for existing clientsImplementation
Follows the direct FFI callback pattern (same as Go PR valkey-io/valkey-glide#5891), not the socket listener/registry pattern used by Python and Node.
valkey-glidesubmodule tob4b34a1dc16dto include the core RustAddressResolvertrait (PR #5328) and the FFI layer changes (PR #5876)AddressResolverCallbackC function pointer type andFFIAddressResolverstruct torust/src/lib.rscreate_clientRust FFI function with an optional 5thaddress_resolverparameterLimitations
Testing
ConnectionConfigurationTests.cscovering builder configuration, defaults, and edge casesAddressResolverTests.cscovering:Related Issues
Checklist
This Pull Request is related to one issue.CHANGELOG.md,README.md,DEVELOPER.md, and other documentation files are updated.mainor releasemain, squash otherwise.