add retry if timeout error for clickhouse

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-18 21:16:07 +02:00
parent 7a0190c186
commit 9ee8626f96
2 changed files with 7 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ const getError = (e: unknown) => {
'Name: ' + e.name,
'Message: ' + e.message,
'Stack: ' + e.stack,
'Cause: ' + e.cause,
'Cause: ' + (e.cause ? String(e.cause) : ''),
].join('\n');
}
return 'Unknown error';

View File

@@ -7,9 +7,10 @@ export const originalCh = createClient({
password: process.env.CLICKHOUSE_PASSWORD,
database: process.env.CLICKHOUSE_DB,
max_open_connections: 10,
request_timeout: 10000,
keep_alive: {
enabled: true,
idle_socket_ttl: 5000,
idle_socket_ttl: 8000,
},
compression: {
request: true,
@@ -29,10 +30,11 @@ export const ch = new Proxy(originalCh, {
} catch (error: unknown) {
if (
error instanceof Error &&
error.message.includes('socket hang up')
(error.message.includes('socket hang up') ||
error.message.includes('Timeout error'))
) {
console.error(
`Caught socket hang up error on ${property.toString()}, retrying once.`
console.info(
`Caught ${error.message} error on ${property.toString()}, retrying once.`
);
await new Promise((resolve) => setTimeout(resolve, 500));
try {