diff --git a/README.md b/README.md index 8204bc4..8809464 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ const options: ClientOptions = { host: '127.0.0.1', port: 50051, headers: [], + + // Optional timeout and keep-alive settings (all in seconds) + connectTimeout: 30, // Connection timeout (default: 20) + timeout: 60, // Request timeout (default: 20) + keepAliveInterval: 120, // Keep-alive ping interval (default: 300) + keepAliveTimeout: 30, // Keep-alive response timeout (default: 20) }; const client = await createFlightSqlClient(options); @@ -52,6 +58,19 @@ const buffer = await client.getTables({ includeSchema: true }); const table = tableFromIPC(buffer); ``` +## Configuration Options + +The `ClientOptions` interface supports the following timeout and connection settings: + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `connectTimeout` | `number?` | 20 | Maximum time in seconds to wait for initial connection | +| `timeout` | `number?` | 20 | Maximum time in seconds to wait for individual requests | +| `keepAliveInterval` | `number?` | 300 | Interval in seconds between keep-alive pings | +| `keepAliveTimeout` | `number?` | 20 | Maximum time in seconds to wait for keep-alive responses | + +All timeout values are optional and specified in seconds. If not provided, they default to 300 seconds (5 minutes). + ## Development Requirements: diff --git a/index.d.ts b/index.d.ts index 859174e..ed690a9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -27,9 +27,17 @@ export interface ClientOptions { host: string; /** Server port. */ port?: number; + /** Connection timeout in seconds */ + connectTimeout?: number; + /** Request timeout in seconds */ + timeout?: number; + /** Keep alive interval in seconds */ + keepAliveInterval?: number; + /** Keep alive timeout in seconds */ + keepAliveTimeout?: number; } -export function createFlightSqlClient(options: ClientOptions): Promise; -export function rustCrateVersion(): string; +export declare function createFlightSqlClient(options: ClientOptions): Promise; +export declare function rustCrateVersion(): string; export interface GetDbSchemasOptions { /** * Specifies the Catalog to search for the tables. diff --git a/src/flight_client.rs b/src/flight_client.rs index ef1b378..4fdc2c1 100644 --- a/src/flight_client.rs +++ b/src/flight_client.rs @@ -45,6 +45,18 @@ pub struct ClientOptions { /// Server port. pub port: Option, + + /// Connection timeout in seconds + pub connect_timeout: Option, + + /// Request timeout in seconds + pub timeout: Option, + + /// Keep alive interval in seconds + pub keep_alive_interval: Option, + + /// Keep alive timeout in seconds + pub keep_alive_timeout: Option, } pub(crate) async fn execute_flight( @@ -117,12 +129,12 @@ pub(crate) async fn setup_client( let mut endpoint = Endpoint::new(format!("{}://{}:{}", protocol, args.host, port)) .map_err(|err| ArrowError::ExternalError(Box::new(err)))? - .connect_timeout(Duration::from_secs(20)) - .timeout(Duration::from_secs(20)) + .connect_timeout(Duration::from_secs(args.connect_timeout.unwrap_or(20) as u64)) + .timeout(Duration::from_secs(args.timeout.unwrap_or(20) as u64)) .tcp_nodelay(true) // Disable Nagle's Algorithm since we don't want packets to wait .tcp_keepalive(Option::Some(Duration::from_secs(3600))) - .http2_keep_alive_interval(Duration::from_secs(300)) - .keep_alive_timeout(Duration::from_secs(20)) + .http2_keep_alive_interval(Duration::from_secs(args.keep_alive_interval.unwrap_or(300) as u64)) + .keep_alive_timeout(Duration::from_secs(args.keep_alive_timeout.unwrap_or(20) as u64)) .keep_alive_while_idle(true); if args.tls {