Skip to content

Commit 2199122

Browse files
authored
Add a zero sleep macrotask before the request (#296)
1 parent 899b34a commit 2199122

File tree

8 files changed

+20
-7
lines changed

8 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# 1.5.0 (Node.js, Web)
1+
# 1.4.1 (Node.js, Web)
22

3-
## New features
3+
## Improvements
4+
5+
- `ClickHouseClient` is now exported as a value from `@clickhouse/client` and `@clickhouse/client-web` packages, allowing for better integration in dependency injection frameworks that rely on IoC (e.g., [Nest.js](https://github.com/nestjs/nest), [tsyringe](https://github.com/microsoft/tsyringe)) ([@mathieu-bour](https://github.com/mathieu-bour), [#292](https://github.com/ClickHouse/clickhouse-js/issues/292)).
6+
7+
## Bug fixes
48

5-
- `ClickHouseClient` is now exported as a value from packages, allowing to a better integration in dependency injection frameworks which rely on IoC.
9+
- Fixed a potential socket hang up issue that could happen under 100% CPU load ([#294](https://github.com/ClickHouse/clickhouse-js/issues/294)).
610

711
# 1.4.0 (Node.js)
812

packages/client-common/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ export {
8080
numberConfigURLValue,
8181
} from './config'
8282
export {
83-
withCompressionHeaders,
8483
isSuccessfulResponse,
84+
sleep,
8585
toSearchParams,
8686
transformUrl,
87+
withCompressionHeaders,
8788
withHttpSettings,
8889
} from './utils'
8990
export { LogWriter, DefaultLogger, type LogWriterParams } from './logger'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './connection'
2+
export * from './sleep'
23
export * from './url'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function sleep(ms: number) {
2+
await new Promise((resolve) => setTimeout(resolve, ms))
3+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default '1.4.0'
1+
export default '1.4.1'

packages/client-node/src/connection/node_base_connection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
LogWriter,
1616
ResponseHeaders,
1717
} from '@clickhouse/client-common'
18+
import { sleep } from '@clickhouse/client-common'
1819
import {
1920
isSuccessfulResponse,
2021
parseError,
@@ -420,6 +421,9 @@ export abstract class NodeBaseConnection
420421
params: RequestParams,
421422
op: ConnOperation,
422423
): Promise<RequestResult> {
424+
// allows the event loop to process the idle socket timers, if the CPU load is high
425+
// otherwise, we can occasionally get an expired socket, see https://github.com/ClickHouse/clickhouse-js/issues/294
426+
await sleep(0)
423427
return new Promise((resolve, reject) => {
424428
const start = Date.now()
425429
const request = this.createClientRequest(params)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default '1.4.0'
1+
export default '1.4.1'

packages/client-web/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default '1.4.0'
1+
export default '1.4.1'

0 commit comments

Comments
 (0)