-
Notifications
You must be signed in to change notification settings - Fork 46
25.11 HTTP stream errors handling #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dd9f13d
Errors in the middle of the stream WIP
slvrtrn 824fcce
Node.js impl for 25.11 HTTP stream errors handling
slvrtrn 6d3eee7
Fix lint, prettier issues, bump a few dev deps
slvrtrn 8c7e419
Check that server version is at least 25.11
slvrtrn dc1c415
Skip test env init for certain test runs
slvrtrn 5edee6e
Add web version error handling and tests, cleanup
slvrtrn 3c2d844
[skip ci] Update CHANGELOG.md
slvrtrn 0fc3163
Improve stream error handling, more tests
slvrtrn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| ## Summary | ||
|
|
||
| A short description of the changes with a link to an open issue. | ||
|
|
||
| ## Checklist | ||
|
|
||
| Delete items not relevant to your PR: | ||
|
|
||
| - [ ] Unit and integration tests covering the common scenarios were added | ||
| - [ ] A human-readable description of the changes was provided to include in CHANGELOG | ||
| - [ ] For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/client-common/__tests__/fixtures/stream_errors.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { QueryParamsWithFormat } from '@clickhouse/client-common' | ||
| import { ClickHouseError } from '@clickhouse/client-common' | ||
|
|
||
| export function streamErrorQueryParams(): QueryParamsWithFormat<'JSONEachRow'> { | ||
| return { | ||
| query: `SELECT toInt32(number) AS n, | ||
| throwIf(number = 10, 'boom') AS e | ||
| FROM system.numbers LIMIT 10000000`, | ||
| format: 'JSONEachRow', | ||
| clickhouse_settings: { | ||
| // enforcing at least a few blocks, so that the response code is 200 OK | ||
| max_block_size: '1', | ||
| // this is false by default since 25.11; no need to set it explicitly | ||
| // http_write_exception_in_output_format: false, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| export function assertError(err: Error | null) { | ||
| expect(err).not.toBeNull() | ||
| expect(err).toBeInstanceOf(ClickHouseError) | ||
|
|
||
| const chErr = err as ClickHouseError | ||
| expect(chErr.message).toContain(`boom: while executing 'FUNCTION throwIf`) | ||
| expect(chErr.code).toBe('395') | ||
| } |
57 changes: 57 additions & 0 deletions
57
packages/client-common/__tests__/unit/stream_utils.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { checkErrorInChunkAtIndex } from '@clickhouse/client-common' | ||
|
|
||
| describe('utils/stream', () => { | ||
| const errMsg = 'boom' | ||
| const tag = 'FOOBAR' | ||
|
|
||
| it('should handle a valid error chunk', async () => { | ||
| const chunk = buildValidErrorChunk(errMsg, tag) | ||
| const newLineIdx = 1 | ||
|
|
||
| const err = checkErrorInChunkAtIndex(chunk, newLineIdx, tag) | ||
| expect(err).toBeDefined() | ||
| expect(err).toBeInstanceOf(Error) | ||
| expect(err!.message).toBe(errMsg) | ||
| }) | ||
|
|
||
| it('should handle a broken chunk', async () => { | ||
| const chunk = new TextEncoder().encode( | ||
| '\r\nsome random data \nthat does not conform\r\t to the protocol\r\n', | ||
| ) | ||
| const newLineIdx = 1 | ||
|
|
||
| const err = checkErrorInChunkAtIndex(chunk, newLineIdx, tag) | ||
| expect(err).toBeDefined() | ||
| expect(err).toBeInstanceOf(Error) | ||
| expect(err?.message).toContain('error in the stream') | ||
| }) | ||
|
|
||
| it('should handle a partial of a valid chunk', async () => { | ||
| const chunk = buildValidErrorChunk(errMsg, tag).slice(0, 20) | ||
| const newLineIdx = 1 | ||
|
|
||
| const err = checkErrorInChunkAtIndex(chunk, newLineIdx, tag) | ||
| expect(err).toBeDefined() | ||
| expect(err).toBeInstanceOf(Error) | ||
| expect(err?.message).toContain('error in the stream') | ||
| }) | ||
| }) | ||
|
|
||
| /** | ||
| * \r\n__exception__\r\nFOOBAR | ||
| * boom | ||
| * 5 FOOBAR\r\n__exception__\r\n | ||
| */ | ||
| export function buildValidErrorChunk(errMsg: string, tag: string): Uint8Array { | ||
| const chunkStr = | ||
| '\r\n__exception__\r\n' + | ||
| tag + | ||
| '\n' + | ||
| errMsg + | ||
| '\n' + | ||
| (errMsg.length + 1) + // +1 to len for the newline character | ||
| ' ' + | ||
| tag + | ||
| '\r\n__exception__\r\n' | ||
| return new TextEncoder().encode(chunkStr) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.