dialoptions.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package grpc
  19. import (
  20. "context"
  21. "fmt"
  22. "net"
  23. "time"
  24. "google.golang.org/grpc/backoff"
  25. "google.golang.org/grpc/balancer"
  26. "google.golang.org/grpc/credentials"
  27. "google.golang.org/grpc/grpclog"
  28. "google.golang.org/grpc/internal"
  29. internalbackoff "google.golang.org/grpc/internal/backoff"
  30. "google.golang.org/grpc/internal/envconfig"
  31. "google.golang.org/grpc/internal/transport"
  32. "google.golang.org/grpc/keepalive"
  33. "google.golang.org/grpc/resolver"
  34. "google.golang.org/grpc/stats"
  35. )
  36. // dialOptions configure a Dial call. dialOptions are set by the DialOption
  37. // values passed to Dial.
  38. type dialOptions struct {
  39. unaryInt UnaryClientInterceptor
  40. streamInt StreamClientInterceptor
  41. chainUnaryInts []UnaryClientInterceptor
  42. chainStreamInts []StreamClientInterceptor
  43. cp Compressor
  44. dc Decompressor
  45. bs internalbackoff.Strategy
  46. block bool
  47. insecure bool
  48. timeout time.Duration
  49. scChan <-chan ServiceConfig
  50. authority string
  51. copts transport.ConnectOptions
  52. callOptions []CallOption
  53. // This is used by v1 balancer dial option WithBalancer to support v1
  54. // balancer, and also by WithBalancerName dial option.
  55. balancerBuilder balancer.Builder
  56. // This is to support grpclb.
  57. resolverBuilder resolver.Builder
  58. channelzParentID int64
  59. disableServiceConfig bool
  60. disableRetry bool
  61. disableHealthCheck bool
  62. healthCheckFunc internal.HealthChecker
  63. minConnectTimeout func() time.Duration
  64. defaultServiceConfig *ServiceConfig // defaultServiceConfig is parsed from defaultServiceConfigRawJSON.
  65. defaultServiceConfigRawJSON *string
  66. // This is used by ccResolverWrapper to backoff between successive calls to
  67. // resolver.ResolveNow(). The user will have no need to configure this, but
  68. // we need to be able to configure this in tests.
  69. resolveNowBackoff func(int) time.Duration
  70. }
  71. // DialOption configures how we set up the connection.
  72. type DialOption interface {
  73. apply(*dialOptions)
  74. }
  75. // EmptyDialOption does not alter the dial configuration. It can be embedded in
  76. // another structure to build custom dial options.
  77. //
  78. // This API is EXPERIMENTAL.
  79. type EmptyDialOption struct{}
  80. func (EmptyDialOption) apply(*dialOptions) {}
  81. // funcDialOption wraps a function that modifies dialOptions into an
  82. // implementation of the DialOption interface.
  83. type funcDialOption struct {
  84. f func(*dialOptions)
  85. }
  86. func (fdo *funcDialOption) apply(do *dialOptions) {
  87. fdo.f(do)
  88. }
  89. func newFuncDialOption(f func(*dialOptions)) *funcDialOption {
  90. return &funcDialOption{
  91. f: f,
  92. }
  93. }
  94. // WithWriteBufferSize determines how much data can be batched before doing a
  95. // write on the wire. The corresponding memory allocation for this buffer will
  96. // be twice the size to keep syscalls low. The default value for this buffer is
  97. // 32KB.
  98. //
  99. // Zero will disable the write buffer such that each write will be on underlying
  100. // connection. Note: A Send call may not directly translate to a write.
  101. func WithWriteBufferSize(s int) DialOption {
  102. return newFuncDialOption(func(o *dialOptions) {
  103. o.copts.WriteBufferSize = s
  104. })
  105. }
  106. // WithReadBufferSize lets you set the size of read buffer, this determines how
  107. // much data can be read at most for each read syscall.
  108. //
  109. // The default value for this buffer is 32KB. Zero will disable read buffer for
  110. // a connection so data framer can access the underlying conn directly.
  111. func WithReadBufferSize(s int) DialOption {
  112. return newFuncDialOption(func(o *dialOptions) {
  113. o.copts.ReadBufferSize = s
  114. })
  115. }
  116. // WithInitialWindowSize returns a DialOption which sets the value for initial
  117. // window size on a stream. The lower bound for window size is 64K and any value
  118. // smaller than that will be ignored.
  119. func WithInitialWindowSize(s int32) DialOption {
  120. return newFuncDialOption(func(o *dialOptions) {
  121. o.copts.InitialWindowSize = s
  122. })
  123. }
  124. // WithInitialConnWindowSize returns a DialOption which sets the value for
  125. // initial window size on a connection. The lower bound for window size is 64K
  126. // and any value smaller than that will be ignored.
  127. func WithInitialConnWindowSize(s int32) DialOption {
  128. return newFuncDialOption(func(o *dialOptions) {
  129. o.copts.InitialConnWindowSize = s
  130. })
  131. }
  132. // WithMaxMsgSize returns a DialOption which sets the maximum message size the
  133. // client can receive.
  134. //
  135. // Deprecated: use WithDefaultCallOptions(MaxCallRecvMsgSize(s)) instead. Will
  136. // be supported throughout 1.x.
  137. func WithMaxMsgSize(s int) DialOption {
  138. return WithDefaultCallOptions(MaxCallRecvMsgSize(s))
  139. }
  140. // WithDefaultCallOptions returns a DialOption which sets the default
  141. // CallOptions for calls over the connection.
  142. func WithDefaultCallOptions(cos ...CallOption) DialOption {
  143. return newFuncDialOption(func(o *dialOptions) {
  144. o.callOptions = append(o.callOptions, cos...)
  145. })
  146. }
  147. // WithCodec returns a DialOption which sets a codec for message marshaling and
  148. // unmarshaling.
  149. //
  150. // Deprecated: use WithDefaultCallOptions(ForceCodec(_)) instead. Will be
  151. // supported throughout 1.x.
  152. func WithCodec(c Codec) DialOption {
  153. return WithDefaultCallOptions(CallCustomCodec(c))
  154. }
  155. // WithCompressor returns a DialOption which sets a Compressor to use for
  156. // message compression. It has lower priority than the compressor set by the
  157. // UseCompressor CallOption.
  158. //
  159. // Deprecated: use UseCompressor instead. Will be supported throughout 1.x.
  160. func WithCompressor(cp Compressor) DialOption {
  161. return newFuncDialOption(func(o *dialOptions) {
  162. o.cp = cp
  163. })
  164. }
  165. // WithDecompressor returns a DialOption which sets a Decompressor to use for
  166. // incoming message decompression. If incoming response messages are encoded
  167. // using the decompressor's Type(), it will be used. Otherwise, the message
  168. // encoding will be used to look up the compressor registered via
  169. // encoding.RegisterCompressor, which will then be used to decompress the
  170. // message. If no compressor is registered for the encoding, an Unimplemented
  171. // status error will be returned.
  172. //
  173. // Deprecated: use encoding.RegisterCompressor instead. Will be supported
  174. // throughout 1.x.
  175. func WithDecompressor(dc Decompressor) DialOption {
  176. return newFuncDialOption(func(o *dialOptions) {
  177. o.dc = dc
  178. })
  179. }
  180. // WithBalancer returns a DialOption which sets a load balancer with the v1 API.
  181. // Name resolver will be ignored if this DialOption is specified.
  182. //
  183. // Deprecated: use the new balancer APIs in balancer package and
  184. // WithBalancerName. Will be removed in a future 1.x release.
  185. func WithBalancer(b Balancer) DialOption {
  186. return newFuncDialOption(func(o *dialOptions) {
  187. o.balancerBuilder = &balancerWrapperBuilder{
  188. b: b,
  189. }
  190. })
  191. }
  192. // WithBalancerName sets the balancer that the ClientConn will be initialized
  193. // with. Balancer registered with balancerName will be used. This function
  194. // panics if no balancer was registered by balancerName.
  195. //
  196. // The balancer cannot be overridden by balancer option specified by service
  197. // config.
  198. //
  199. // Deprecated: use WithDefaultServiceConfig and WithDisableServiceConfig
  200. // instead. Will be removed in a future 1.x release.
  201. func WithBalancerName(balancerName string) DialOption {
  202. builder := balancer.Get(balancerName)
  203. if builder == nil {
  204. panic(fmt.Sprintf("grpc.WithBalancerName: no balancer is registered for name %v", balancerName))
  205. }
  206. return newFuncDialOption(func(o *dialOptions) {
  207. o.balancerBuilder = builder
  208. })
  209. }
  210. // withResolverBuilder is only for grpclb.
  211. func withResolverBuilder(b resolver.Builder) DialOption {
  212. return newFuncDialOption(func(o *dialOptions) {
  213. o.resolverBuilder = b
  214. })
  215. }
  216. // WithServiceConfig returns a DialOption which has a channel to read the
  217. // service configuration.
  218. //
  219. // Deprecated: service config should be received through name resolver or via
  220. // WithDefaultServiceConfig, as specified at
  221. // https://github.com/grpc/grpc/blob/master/doc/service_config.md. Will be
  222. // removed in a future 1.x release.
  223. func WithServiceConfig(c <-chan ServiceConfig) DialOption {
  224. return newFuncDialOption(func(o *dialOptions) {
  225. o.scChan = c
  226. })
  227. }
  228. // WithConnectParams configures the dialer to use the provided ConnectParams.
  229. //
  230. // The backoff configuration specified as part of the ConnectParams overrides
  231. // all defaults specified in
  232. // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md. Consider
  233. // using the backoff.DefaultConfig as a base, in cases where you want to
  234. // override only a subset of the backoff configuration.
  235. //
  236. // This API is EXPERIMENTAL.
  237. func WithConnectParams(p ConnectParams) DialOption {
  238. return newFuncDialOption(func(o *dialOptions) {
  239. o.bs = internalbackoff.Exponential{Config: p.Backoff}
  240. o.minConnectTimeout = func() time.Duration {
  241. return p.MinConnectTimeout
  242. }
  243. })
  244. }
  245. // WithBackoffMaxDelay configures the dialer to use the provided maximum delay
  246. // when backing off after failed connection attempts.
  247. //
  248. // Deprecated: use WithConnectParams instead. Will be supported throughout 1.x.
  249. func WithBackoffMaxDelay(md time.Duration) DialOption {
  250. return WithBackoffConfig(BackoffConfig{MaxDelay: md})
  251. }
  252. // WithBackoffConfig configures the dialer to use the provided backoff
  253. // parameters after connection failures.
  254. //
  255. // Deprecated: use WithConnectParams instead. Will be supported throughout 1.x.
  256. func WithBackoffConfig(b BackoffConfig) DialOption {
  257. bc := backoff.DefaultConfig
  258. bc.MaxDelay = b.MaxDelay
  259. return withBackoff(internalbackoff.Exponential{Config: bc})
  260. }
  261. // withBackoff sets the backoff strategy used for connectRetryNum after a failed
  262. // connection attempt.
  263. //
  264. // This can be exported if arbitrary backoff strategies are allowed by gRPC.
  265. func withBackoff(bs internalbackoff.Strategy) DialOption {
  266. return newFuncDialOption(func(o *dialOptions) {
  267. o.bs = bs
  268. })
  269. }
  270. // WithBlock returns a DialOption which makes caller of Dial blocks until the
  271. // underlying connection is up. Without this, Dial returns immediately and
  272. // connecting the server happens in background.
  273. func WithBlock() DialOption {
  274. return newFuncDialOption(func(o *dialOptions) {
  275. o.block = true
  276. })
  277. }
  278. // WithInsecure returns a DialOption which disables transport security for this
  279. // ClientConn. Note that transport security is required unless WithInsecure is
  280. // set.
  281. func WithInsecure() DialOption {
  282. return newFuncDialOption(func(o *dialOptions) {
  283. o.insecure = true
  284. })
  285. }
  286. // WithTransportCredentials returns a DialOption which configures a connection
  287. // level security credentials (e.g., TLS/SSL). This should not be used together
  288. // with WithCredentialsBundle.
  289. func WithTransportCredentials(creds credentials.TransportCredentials) DialOption {
  290. return newFuncDialOption(func(o *dialOptions) {
  291. o.copts.TransportCredentials = creds
  292. })
  293. }
  294. // WithPerRPCCredentials returns a DialOption which sets credentials and places
  295. // auth state on each outbound RPC.
  296. func WithPerRPCCredentials(creds credentials.PerRPCCredentials) DialOption {
  297. return newFuncDialOption(func(o *dialOptions) {
  298. o.copts.PerRPCCredentials = append(o.copts.PerRPCCredentials, creds)
  299. })
  300. }
  301. // WithCredentialsBundle returns a DialOption to set a credentials bundle for
  302. // the ClientConn.WithCreds. This should not be used together with
  303. // WithTransportCredentials.
  304. //
  305. // This API is experimental.
  306. func WithCredentialsBundle(b credentials.Bundle) DialOption {
  307. return newFuncDialOption(func(o *dialOptions) {
  308. o.copts.CredsBundle = b
  309. })
  310. }
  311. // WithTimeout returns a DialOption that configures a timeout for dialing a
  312. // ClientConn initially. This is valid if and only if WithBlock() is present.
  313. //
  314. // Deprecated: use DialContext instead of Dial and context.WithTimeout
  315. // instead. Will be supported throughout 1.x.
  316. func WithTimeout(d time.Duration) DialOption {
  317. return newFuncDialOption(func(o *dialOptions) {
  318. o.timeout = d
  319. })
  320. }
  321. // WithContextDialer returns a DialOption that sets a dialer to create
  322. // connections. If FailOnNonTempDialError() is set to true, and an error is
  323. // returned by f, gRPC checks the error's Temporary() method to decide if it
  324. // should try to reconnect to the network address.
  325. func WithContextDialer(f func(context.Context, string) (net.Conn, error)) DialOption {
  326. return newFuncDialOption(func(o *dialOptions) {
  327. o.copts.Dialer = f
  328. })
  329. }
  330. func init() {
  331. internal.WithResolverBuilder = withResolverBuilder
  332. internal.WithHealthCheckFunc = withHealthCheckFunc
  333. }
  334. // WithDialer returns a DialOption that specifies a function to use for dialing
  335. // network addresses. If FailOnNonTempDialError() is set to true, and an error
  336. // is returned by f, gRPC checks the error's Temporary() method to decide if it
  337. // should try to reconnect to the network address.
  338. //
  339. // Deprecated: use WithContextDialer instead. Will be supported throughout
  340. // 1.x.
  341. func WithDialer(f func(string, time.Duration) (net.Conn, error)) DialOption {
  342. return WithContextDialer(
  343. func(ctx context.Context, addr string) (net.Conn, error) {
  344. if deadline, ok := ctx.Deadline(); ok {
  345. return f(addr, time.Until(deadline))
  346. }
  347. return f(addr, 0)
  348. })
  349. }
  350. // WithStatsHandler returns a DialOption that specifies the stats handler for
  351. // all the RPCs and underlying network connections in this ClientConn.
  352. func WithStatsHandler(h stats.Handler) DialOption {
  353. return newFuncDialOption(func(o *dialOptions) {
  354. o.copts.StatsHandler = h
  355. })
  356. }
  357. // FailOnNonTempDialError returns a DialOption that specifies if gRPC fails on
  358. // non-temporary dial errors. If f is true, and dialer returns a non-temporary
  359. // error, gRPC will fail the connection to the network address and won't try to
  360. // reconnect. The default value of FailOnNonTempDialError is false.
  361. //
  362. // FailOnNonTempDialError only affects the initial dial, and does not do
  363. // anything useful unless you are also using WithBlock().
  364. //
  365. // This is an EXPERIMENTAL API.
  366. func FailOnNonTempDialError(f bool) DialOption {
  367. return newFuncDialOption(func(o *dialOptions) {
  368. o.copts.FailOnNonTempDialError = f
  369. })
  370. }
  371. // WithUserAgent returns a DialOption that specifies a user agent string for all
  372. // the RPCs.
  373. func WithUserAgent(s string) DialOption {
  374. return newFuncDialOption(func(o *dialOptions) {
  375. o.copts.UserAgent = s
  376. })
  377. }
  378. // WithKeepaliveParams returns a DialOption that specifies keepalive parameters
  379. // for the client transport.
  380. func WithKeepaliveParams(kp keepalive.ClientParameters) DialOption {
  381. if kp.Time < internal.KeepaliveMinPingTime {
  382. grpclog.Warningf("Adjusting keepalive ping interval to minimum period of %v", internal.KeepaliveMinPingTime)
  383. kp.Time = internal.KeepaliveMinPingTime
  384. }
  385. return newFuncDialOption(func(o *dialOptions) {
  386. o.copts.KeepaliveParams = kp
  387. })
  388. }
  389. // WithUnaryInterceptor returns a DialOption that specifies the interceptor for
  390. // unary RPCs.
  391. func WithUnaryInterceptor(f UnaryClientInterceptor) DialOption {
  392. return newFuncDialOption(func(o *dialOptions) {
  393. o.unaryInt = f
  394. })
  395. }
  396. // WithChainUnaryInterceptor returns a DialOption that specifies the chained
  397. // interceptor for unary RPCs. The first interceptor will be the outer most,
  398. // while the last interceptor will be the inner most wrapper around the real call.
  399. // All interceptors added by this method will be chained, and the interceptor
  400. // defined by WithUnaryInterceptor will always be prepended to the chain.
  401. func WithChainUnaryInterceptor(interceptors ...UnaryClientInterceptor) DialOption {
  402. return newFuncDialOption(func(o *dialOptions) {
  403. o.chainUnaryInts = append(o.chainUnaryInts, interceptors...)
  404. })
  405. }
  406. // WithStreamInterceptor returns a DialOption that specifies the interceptor for
  407. // streaming RPCs.
  408. func WithStreamInterceptor(f StreamClientInterceptor) DialOption {
  409. return newFuncDialOption(func(o *dialOptions) {
  410. o.streamInt = f
  411. })
  412. }
  413. // WithChainStreamInterceptor returns a DialOption that specifies the chained
  414. // interceptor for unary RPCs. The first interceptor will be the outer most,
  415. // while the last interceptor will be the inner most wrapper around the real call.
  416. // All interceptors added by this method will be chained, and the interceptor
  417. // defined by WithStreamInterceptor will always be prepended to the chain.
  418. func WithChainStreamInterceptor(interceptors ...StreamClientInterceptor) DialOption {
  419. return newFuncDialOption(func(o *dialOptions) {
  420. o.chainStreamInts = append(o.chainStreamInts, interceptors...)
  421. })
  422. }
  423. // WithAuthority returns a DialOption that specifies the value to be used as the
  424. // :authority pseudo-header. This value only works with WithInsecure and has no
  425. // effect if TransportCredentials are present.
  426. func WithAuthority(a string) DialOption {
  427. return newFuncDialOption(func(o *dialOptions) {
  428. o.authority = a
  429. })
  430. }
  431. // WithChannelzParentID returns a DialOption that specifies the channelz ID of
  432. // current ClientConn's parent. This function is used in nested channel creation
  433. // (e.g. grpclb dial).
  434. //
  435. // This API is EXPERIMENTAL.
  436. func WithChannelzParentID(id int64) DialOption {
  437. return newFuncDialOption(func(o *dialOptions) {
  438. o.channelzParentID = id
  439. })
  440. }
  441. // WithDisableServiceConfig returns a DialOption that causes gRPC to ignore any
  442. // service config provided by the resolver and provides a hint to the resolver
  443. // to not fetch service configs.
  444. //
  445. // Note that this dial option only disables service config from resolver. If
  446. // default service config is provided, gRPC will use the default service config.
  447. func WithDisableServiceConfig() DialOption {
  448. return newFuncDialOption(func(o *dialOptions) {
  449. o.disableServiceConfig = true
  450. })
  451. }
  452. // WithDefaultServiceConfig returns a DialOption that configures the default
  453. // service config, which will be used in cases where:
  454. //
  455. // 1. WithDisableServiceConfig is also used.
  456. // 2. Resolver does not return a service config or if the resolver returns an
  457. // invalid service config.
  458. //
  459. // This API is EXPERIMENTAL.
  460. func WithDefaultServiceConfig(s string) DialOption {
  461. return newFuncDialOption(func(o *dialOptions) {
  462. o.defaultServiceConfigRawJSON = &s
  463. })
  464. }
  465. // WithDisableRetry returns a DialOption that disables retries, even if the
  466. // service config enables them. This does not impact transparent retries, which
  467. // will happen automatically if no data is written to the wire or if the RPC is
  468. // unprocessed by the remote server.
  469. //
  470. // Retry support is currently disabled by default, but will be enabled by
  471. // default in the future. Until then, it may be enabled by setting the
  472. // environment variable "GRPC_GO_RETRY" to "on".
  473. //
  474. // This API is EXPERIMENTAL.
  475. func WithDisableRetry() DialOption {
  476. return newFuncDialOption(func(o *dialOptions) {
  477. o.disableRetry = true
  478. })
  479. }
  480. // WithMaxHeaderListSize returns a DialOption that specifies the maximum
  481. // (uncompressed) size of header list that the client is prepared to accept.
  482. func WithMaxHeaderListSize(s uint32) DialOption {
  483. return newFuncDialOption(func(o *dialOptions) {
  484. o.copts.MaxHeaderListSize = &s
  485. })
  486. }
  487. // WithDisableHealthCheck disables the LB channel health checking for all
  488. // SubConns of this ClientConn.
  489. //
  490. // This API is EXPERIMENTAL.
  491. func WithDisableHealthCheck() DialOption {
  492. return newFuncDialOption(func(o *dialOptions) {
  493. o.disableHealthCheck = true
  494. })
  495. }
  496. // withHealthCheckFunc replaces the default health check function with the
  497. // provided one. It makes tests easier to change the health check function.
  498. //
  499. // For testing purpose only.
  500. func withHealthCheckFunc(f internal.HealthChecker) DialOption {
  501. return newFuncDialOption(func(o *dialOptions) {
  502. o.healthCheckFunc = f
  503. })
  504. }
  505. func defaultDialOptions() dialOptions {
  506. return dialOptions{
  507. disableRetry: !envconfig.Retry,
  508. healthCheckFunc: internal.HealthCheckFunc,
  509. copts: transport.ConnectOptions{
  510. WriteBufferSize: defaultWriteBufSize,
  511. ReadBufferSize: defaultReadBufSize,
  512. },
  513. resolveNowBackoff: internalbackoff.DefaultExponential.Backoff,
  514. }
  515. }
  516. // withGetMinConnectDeadline specifies the function that clientconn uses to
  517. // get minConnectDeadline. This can be used to make connection attempts happen
  518. // faster/slower.
  519. //
  520. // For testing purpose only.
  521. func withMinConnectDeadline(f func() time.Duration) DialOption {
  522. return newFuncDialOption(func(o *dialOptions) {
  523. o.minConnectTimeout = f
  524. })
  525. }
  526. // withResolveNowBackoff specifies the function that clientconn uses to backoff
  527. // between successive calls to resolver.ResolveNow().
  528. //
  529. // For testing purpose only.
  530. func withResolveNowBackoff(f func(int) time.Duration) DialOption {
  531. return newFuncDialOption(func(o *dialOptions) {
  532. o.resolveNowBackoff = f
  533. })
  534. }