Skip to content

Commit 3c222b6

Browse files
committed
feat: fix session attach stream abort issues and update version to 6.0.0-alpha.22
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent 3874bbc commit 3c222b6

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

.changeset/chubby-jeans-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ydbjs/query': patch
3+
---
4+
5+
Fix issues when aborting session attach stream

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"changesets": [
1515
"angry-bags-fail",
1616
"beige-groups-tell",
17+
"chubby-jeans-cheat",
1718
"cold-donkeys-wash",
1819
"common-facts-kneel",
1920
"cuddly-cougars-cough",

packages/query/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# @ydbjs/query
22

3+
## 6.0.0-alpha.22
4+
5+
### Patch Changes
6+
7+
- Fix issues when aborting session attach stream
8+
9+
## 6.0.0-alpha.21
10+
11+
### Patch Changes
12+
13+
- Fix cjs bundle issues
14+
- Updated dependencies
15+
- @ydbjs/value@6.0.0-alpha.11
16+
317
## 6.0.0-alpha.20
418

519
### Patch Changes

packages/query/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ydbjs/query",
3-
"version": "6.0.0-alpha.20",
3+
"version": "6.0.0-alpha.22",
44
"description": "High-level, type-safe YQL query and transaction client for YDB. Supports tagged template syntax, parameter binding, transactions, and statistics.",
55
"license": "Apache-2.0",
66
"type": "module",
@@ -13,7 +13,8 @@
1313
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm",
1414
"test": "vitest --run",
1515
"test:watch": "vitest --watch",
16-
"attw": "attw --pack"
16+
"attw": "attw --pack",
17+
"prepublishOnly": "npm run clean && npm run build:cjs && npm run build:esm && npm run attw"
1718
},
1819
"exports": {
1920
".": {
@@ -42,7 +43,7 @@
4243
"@ydbjs/core": "6.0.0-alpha.16",
4344
"@ydbjs/error": "6.0.0-alpha.7",
4445
"@ydbjs/retry": "6.0.0-alpha.10",
45-
"@ydbjs/value": "6.0.0-alpha.10",
46+
"@ydbjs/value": "6.0.0-alpha.11",
4647
"debug": "^4.4.0",
4748
"nice-grpc": "^2.1.12"
4849
},

packages/query/src/index.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Abortable } from 'node:events'
22

33
import { StatusIds_StatusCode } from '@ydbjs/api/operation'
4-
import { QueryServiceDefinition, type SessionState } from '@ydbjs/api/query'
4+
import { QueryServiceDefinition } from '@ydbjs/api/query'
55
import type { Driver } from '@ydbjs/core'
66
import { CommitError, YDBError } from '@ydbjs/error'
77
import { defaultRetryConfig, isRetryableError, retry } from '@ydbjs/retry'
@@ -149,21 +149,10 @@ export function query(driver: Driver): QueryClient {
149149

150150
client = driver.createClient(QueryServiceDefinition, sessionResponse.nodeId)
151151

152-
let attachSession = Promise.withResolvers<SessionState>()
153-
; (async (stream: AsyncIterable<SessionState>) => {
154-
try {
155-
for await (let state of stream) {
156-
signal.throwIfAborted()
157-
attachSession.resolve(state)
158-
}
159-
} catch (err) {
160-
attachSession.reject(err)
161-
}
162-
})(client.attachSession({ sessionId: store.sessionId }, { signal }))
163-
164-
let attachSessionResult = await attachSession.promise
165-
if (attachSessionResult.status !== StatusIds_StatusCode.SUCCESS) {
166-
throw new YDBError(attachSessionResult.status, attachSessionResult.issues)
152+
let attachSession = client.attachSession({ sessionId: store.sessionId })[Symbol.asyncIterator]()
153+
let attachSessionResult = await attachSession.next()
154+
if (attachSessionResult.value.status !== StatusIds_StatusCode.SUCCESS) {
155+
throw new YDBError(attachSessionResult.value.status, attachSessionResult.value.issues)
167156
}
168157

169158
let beginTransactionResult = await client.beginTransaction({

packages/query/src/query.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
ExecMode,
77
QueryServiceDefinition,
88
type QueryStats,
9-
type SessionState,
109
StatsMode,
1110
Syntax,
1211
} from '@ydbjs/api/query'
@@ -132,21 +131,10 @@ export class Query<T extends any[] = unknown[]> extends EventEmitter<QueryEventM
132131
client = this.#driver.createClient(QueryServiceDefinition, nodeId)
133132
this.#cleanup.push(async () => await client.deleteSession({ sessionId }))
134133

135-
let attachSession = Promise.withResolvers<SessionState>()
136-
; (async (stream: AsyncIterable<SessionState>) => {
137-
try {
138-
for await (let state of stream) {
139-
signal.throwIfAborted()
140-
attachSession.resolve(state)
141-
}
142-
} catch (err) {
143-
attachSession.reject(err)
144-
}
145-
})(client.attachSession({ sessionId }, { signal }))
146-
147-
let attachSessionResult = await attachSession.promise
148-
if (attachSessionResult.status !== StatusIds_StatusCode.SUCCESS) {
149-
throw new YDBError(attachSessionResult.status, attachSessionResult.issues)
134+
let attachSession = client.attachSession({ sessionId })[Symbol.asyncIterator]()
135+
let attachSessionResult = await attachSession.next()
136+
if (attachSessionResult.value.status !== StatusIds_StatusCode.SUCCESS) {
137+
throw new YDBError(attachSessionResult.value.status, attachSessionResult.value.issues)
150138
}
151139
}
152140

0 commit comments

Comments
 (0)