@@ -95,6 +95,57 @@ fn build_telemetry_config(
9595 Ok ( telemetry)
9696}
9797
98+ #[ allow( clippy:: too_many_arguments) ]
99+ fn build_http_config (
100+ request_timeout_secs : Option < f64 > ,
101+ retry_min_wait_secs : Option < u64 > ,
102+ retry_max_wait_secs : Option < u64 > ,
103+ retry_max_attempts : Option < u32 > ,
104+ retry_overall_timeout_secs : Option < u64 > ,
105+ http_headers : Option < Vec < ( String , String ) > > ,
106+ ) -> PyResult < Option < databricks_sql_kernel:: HttpConfig > > {
107+ // Zero means "keep the kernel default", matching the C ABI setter. Use a
108+ // float because databricks-sql-python's existing `_socket_timeout` accepts
109+ // fractional seconds.
110+ let request_timeout = match request_timeout_secs {
111+ None | Some ( 0.0 ) => None ,
112+ Some ( s) => Some ( std:: time:: Duration :: try_from_secs_f64 ( s) . map_err ( |_| {
113+ pyo3:: exceptions:: PyValueError :: new_err ( "request_timeout_secs must be finite and >= 0" )
114+ } ) ?) ,
115+ } ;
116+ let has_http_headers = http_headers. as_ref ( ) . is_some_and ( |h| !h. is_empty ( ) ) ;
117+ if request_timeout. is_none ( )
118+ && retry_min_wait_secs. is_none ( )
119+ && retry_max_wait_secs. is_none ( )
120+ && retry_max_attempts. is_none ( )
121+ && retry_overall_timeout_secs. is_none ( )
122+ && !has_http_headers
123+ {
124+ return Ok ( None ) ;
125+ }
126+
127+ let mut http = databricks_sql_kernel:: HttpConfig :: default ( ) ;
128+ if let Some ( timeout) = request_timeout {
129+ http. request_timeout = timeout;
130+ }
131+ if let Some ( s) = retry_min_wait_secs {
132+ http. retry_min_wait = std:: time:: Duration :: from_secs ( s) ;
133+ }
134+ if let Some ( s) = retry_max_wait_secs {
135+ http. retry_max_wait = std:: time:: Duration :: from_secs ( s) ;
136+ }
137+ if let Some ( attempts) = retry_max_attempts {
138+ http. retry_max_retries = attempts. saturating_sub ( 1 ) ;
139+ }
140+ if let Some ( s) = retry_overall_timeout_secs {
141+ http. overall_timeout = std:: time:: Duration :: from_secs ( s) ;
142+ }
143+ if let Some ( headers) = http_headers {
144+ http. custom_headers = headers;
145+ }
146+ Ok ( Some ( http) )
147+ }
148+
98149#[ allow( clippy:: too_many_arguments) ]
99150fn build_driver_system_configuration (
100151 driver_name : Option < String > ,
@@ -183,6 +234,10 @@ impl Session {
183234 /// CloudFetch requests; token-endpoint (auth) calls keep a fixed
184235 /// fast-fail policy.
185236 ///
237+ /// `request_timeout_secs` caps one HTTP request from connect through
238+ /// response-body completion. Unset or `0` keeps the kernel default
239+ /// (120 seconds).
240+ ///
186241 /// `http_headers` is a list of `(name, value)` pairs sent on every
187242 /// request — used to forward the connector's caller headers (which
188243 /// also carry the composed `User-Agent`). The kernel applies them
@@ -223,6 +278,7 @@ impl Session {
223278 tls_skip_hostname_verify=false ,
224279 tls_client_cert=None ,
225280 tls_client_key=None ,
281+ request_timeout_secs=None ,
226282 retry_min_wait_secs=None ,
227283 retry_max_wait_secs=None ,
228284 retry_max_attempts=None ,
@@ -279,6 +335,7 @@ impl Session {
279335 tls_skip_hostname_verify : bool ,
280336 tls_client_cert : Option < Vec < u8 > > ,
281337 tls_client_key : Option < Vec < u8 > > ,
338+ request_timeout_secs : Option < f64 > ,
282339 retry_min_wait_secs : Option < u64 > ,
283340 retry_max_wait_secs : Option < u64 > ,
284341 retry_max_attempts : Option < u32 > ,
@@ -371,9 +428,10 @@ impl Session {
371428 None
372429 } ;
373430
374- // Build an HttpConfig only when the caller tuned retry/backoff
375- // or supplied custom headers; otherwise leave the builder on its
376- // defaults (1s/60s/5-retries, no extra headers).
431+ // Build an HttpConfig only when the caller tuned the per-request
432+ // timeout, retry/backoff, or supplied custom headers; otherwise leave
433+ // the builder on its defaults (120s request timeout,
434+ // 1s/60s/5-retries, no extra headers).
377435 //
378436 // `retry_max_attempts` is the **total** number of attempts
379437 // (matching the connector's `_retry_stop_after_attempts_count`
@@ -387,33 +445,14 @@ impl Session {
387445 // connector forwards its `http_headers`, which also carries the
388446 // composed `User-Agent`). The kernel applies them before its own
389447 // `Authorization` / `x-databricks-org-id`, which always win.
390- let has_http_headers = http_headers. as_ref ( ) . is_some_and ( |h| !h. is_empty ( ) ) ;
391- let http_config = if retry_min_wait_secs. is_some ( )
392- || retry_max_wait_secs. is_some ( )
393- || retry_max_attempts. is_some ( )
394- || retry_overall_timeout_secs. is_some ( )
395- || has_http_headers
396- {
397- let mut http = databricks_sql_kernel:: HttpConfig :: default ( ) ;
398- if let Some ( s) = retry_min_wait_secs {
399- http. retry_min_wait = std:: time:: Duration :: from_secs ( s) ;
400- }
401- if let Some ( s) = retry_max_wait_secs {
402- http. retry_max_wait = std:: time:: Duration :: from_secs ( s) ;
403- }
404- if let Some ( attempts) = retry_max_attempts {
405- http. retry_max_retries = attempts. saturating_sub ( 1 ) ;
406- }
407- if let Some ( s) = retry_overall_timeout_secs {
408- http. overall_timeout = std:: time:: Duration :: from_secs ( s) ;
409- }
410- if let Some ( headers) = http_headers {
411- http. custom_headers = headers;
412- }
413- Some ( http)
414- } else {
415- None
416- } ;
448+ let http_config = build_http_config (
449+ request_timeout_secs,
450+ retry_min_wait_secs,
451+ retry_max_wait_secs,
452+ retry_max_attempts,
453+ retry_overall_timeout_secs,
454+ http_headers,
455+ ) ?;
417456
418457 let driver_system_configuration = build_driver_system_configuration (
419458 driver_name,
@@ -635,6 +674,27 @@ mod send_sync_tests {
635674 assert ! ( build_telemetry_config( false , None , None , None , None , Some ( 0 ) ) . is_err( ) ) ;
636675 }
637676
677+ #[ test]
678+ fn request_timeout_kwarg_maps_to_http_config ( ) {
679+ let default = databricks_sql_kernel:: HttpConfig :: default ( ) ;
680+ assert ! ( build_http_config( None , None , None , None , None , None )
681+ . unwrap( )
682+ . is_none( ) ) ;
683+ assert ! ( build_http_config( Some ( 0.0 ) , None , None , None , None , None )
684+ . unwrap( )
685+ . is_none( ) ) ;
686+
687+ let http = build_http_config ( Some ( 0.5 ) , None , None , None , None , None )
688+ . unwrap ( )
689+ . expect ( "positive request timeout should build an HTTP config" ) ;
690+ assert_eq ! ( http. request_timeout, std:: time:: Duration :: from_millis( 500 ) ) ;
691+ assert_eq ! ( http. retry_min_wait, default . retry_min_wait) ;
692+ assert_eq ! ( http. overall_timeout, default . overall_timeout) ;
693+
694+ assert ! ( build_http_config( Some ( -1.0 ) , None , None , None , None , None ) . is_err( ) ) ;
695+ assert ! ( build_http_config( Some ( f64 :: NAN ) , None , None , None , None , None ) . is_err( ) ) ;
696+ }
697+
638698 #[ test]
639699 fn driver_system_kwargs_map_to_kernel_config ( ) {
640700 assert ! ( build_driver_system_configuration(
0 commit comments