@@ -4,6 +4,7 @@ import { GeneralError } from '@openfeature/server-sdk';
4
4
import { FlagSyncServiceClient , SyncFlagsRequest , SyncFlagsResponse } from '../../../../proto/ts/sync/v1/sync_service' ;
5
5
import { Config } from '../../../configuration' ;
6
6
import { DataFetch } from '../data-fetch' ;
7
+ import { closeStreamIfDefined } from '../../common' ;
7
8
8
9
/**
9
10
* Implements the gRPC sync contract to fetch flag data.
@@ -34,15 +35,14 @@ export class GrpcFetch implements DataFetch {
34
35
changedCallback : ( flagsChanged : string [ ] ) => void ,
35
36
disconnectCallback : ( ) => void ,
36
37
) : Promise < void > {
37
- // note that we never reject the promise as sync is a long-running operation
38
38
return new Promise ( ( resolve , reject ) =>
39
39
this . listen ( dataFillCallback , reconnectCallback , changedCallback , disconnectCallback , resolve , reject ) ,
40
40
) ;
41
41
}
42
42
43
43
disconnect ( ) {
44
44
this . _logger ?. debug ( 'Disconnecting gRPC sync connection' ) ;
45
- this . _syncStream ?. destroy ( ) ;
45
+ closeStreamIfDefined ( this . _syncStream ) ;
46
46
this . _syncClient . close ( ) ;
47
47
}
48
48
@@ -54,6 +54,7 @@ export class GrpcFetch implements DataFetch {
54
54
resolveConnect ?: ( ) => void ,
55
55
rejectConnect ?: ( reason : Error ) => void ,
56
56
) {
57
+ closeStreamIfDefined ( this . _syncStream ) ;
57
58
this . _syncStream = this . _syncClient . syncFlags ( this . _request ) ;
58
59
59
60
this . _syncStream . on ( 'data' , ( data : SyncFlagsResponse ) => {
0 commit comments