Skip to content

Commit

Permalink
Add a zero sleep macrotask before the request (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
slvrtrn authored Aug 7, 2024
1 parent 899b34a commit 2199122
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# 1.5.0 (Node.js, Web)
# 1.4.1 (Node.js, Web)

## New features
## Improvements

- `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)).

## Bug fixes

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

# 1.4.0 (Node.js)

Expand Down
3 changes: 2 additions & 1 deletion packages/client-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ export {
numberConfigURLValue,
} from './config'
export {
withCompressionHeaders,
isSuccessfulResponse,
sleep,
toSearchParams,
transformUrl,
withCompressionHeaders,
withHttpSettings,
} from './utils'
export { LogWriter, DefaultLogger, type LogWriterParams } from './logger'
Expand Down
1 change: 1 addition & 0 deletions packages/client-common/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './connection'
export * from './sleep'
export * from './url'
3 changes: 3 additions & 0 deletions packages/client-common/src/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function sleep(ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms))
}
2 changes: 1 addition & 1 deletion packages/client-common/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.4.0'
export default '1.4.1'
4 changes: 4 additions & 0 deletions packages/client-node/src/connection/node_base_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
LogWriter,
ResponseHeaders,
} from '@clickhouse/client-common'
import { sleep } from '@clickhouse/client-common'
import {
isSuccessfulResponse,
parseError,
Expand Down Expand Up @@ -420,6 +421,9 @@ export abstract class NodeBaseConnection
params: RequestParams,
op: ConnOperation,
): Promise<RequestResult> {
// allows the event loop to process the idle socket timers, if the CPU load is high
// otherwise, we can occasionally get an expired socket, see https://github.com/ClickHouse/clickhouse-js/issues/294
await sleep(0)
return new Promise((resolve, reject) => {
const start = Date.now()
const request = this.createClientRequest(params)
Expand Down
2 changes: 1 addition & 1 deletion packages/client-node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.4.0'
export default '1.4.1'
2 changes: 1 addition & 1 deletion packages/client-web/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.4.0'
export default '1.4.1'

0 comments on commit 2199122

Please sign in to comment.