Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlightSqlClient>;
export function rustCrateVersion(): string;
export declare function createFlightSqlClient(options: ClientOptions): Promise<FlightSqlClient>;
export declare function rustCrateVersion(): string;
export interface GetDbSchemasOptions {
/**
* Specifies the Catalog to search for the tables.
Expand Down
20 changes: 16 additions & 4 deletions src/flight_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ pub struct ClientOptions {

/// Server port.
pub port: Option<u16>,

/// Connection timeout in seconds
pub connect_timeout: Option<u32>,

/// Request timeout in seconds
pub timeout: Option<u32>,

/// Keep alive interval in seconds
pub keep_alive_interval: Option<u32>,

/// Keep alive timeout in seconds
pub keep_alive_timeout: Option<u32>,
}

pub(crate) async fn execute_flight(
Expand Down Expand Up @@ -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 {
Expand Down