File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
packages/common/src/client/sync/stream Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @powersync/common ' : patch
3+ ---
4+
5+ Improved potential race condition when closing HTTP stream connections.
Original file line number Diff line number Diff line change @@ -6,8 +6,9 @@ import PACKAGE from '../../../../package.json' with { type: 'json' };
66import { AbortOperation } from '../../../utils/AbortOperation.js' ;
77import { DataStream } from '../../../utils/DataStream.js' ;
88import { PowerSyncCredentials } from '../../connection/PowerSyncCredentials.js' ;
9- import { StreamingSyncRequest } from './streaming-sync-types.js' ;
109import { WebsocketClientTransport } from './WebsocketClientTransport.js' ;
10+ import { StreamingSyncRequest } from './streaming-sync-types.js' ;
11+ ;
1112
1213export type BSONImplementation = typeof BSON ;
1314
@@ -557,9 +558,11 @@ export abstract class AbstractRemote {
557558 // Create a new stream splitting the response at line endings while also handling cancellations
558559 // by closing the reader.
559560 const reader = res . body . getReader ( ) ;
561+ let readerReleased = false ;
560562 // This will close the network request and read stream
561563 const closeReader = async ( ) => {
562564 try {
565+ readerReleased = true ;
563566 await reader . cancel ( ) ;
564567 } catch ( ex ) {
565568 // an error will throw if the reader hasn't been used yet
@@ -581,6 +584,9 @@ export abstract class AbstractRemote {
581584
582585 const l = stream . registerListener ( {
583586 lowWater : async ( ) => {
587+ if ( stream . closed || abortSignal ?. aborted || readerReleased ) {
588+ return
589+ }
584590 try {
585591 let didCompleteLine = false ;
586592 while ( ! didCompleteLine ) {
You can’t perform that action at this time.
0 commit comments