@@ -299,11 +299,8 @@ export class ClientSession
299
299
if ( serverSession != null ) {
300
300
// release the server session back to the pool
301
301
this . sessionPool . release ( serverSession ) ;
302
- // Make sure a new serverSession never makes it onto this ClientSession
303
- Object . defineProperty ( this , kServerSession , {
304
- value : ServerSession . clone ( serverSession ) ,
305
- writable : false
306
- } ) ;
302
+ // Store a clone of the server session for reference (debugging)
303
+ this [ kServerSession ] = new ServerSession ( serverSession ) ;
307
304
}
308
305
// mark the session as ended, and emit a signal
309
306
this . hasEnded = true ;
@@ -973,7 +970,18 @@ export class ServerSession {
973
970
isDirty : boolean ;
974
971
975
972
/** @internal */
976
- constructor ( ) {
973
+ constructor (
974
+ cloned ?: { id : ServerSessionId ; lastUse : number ; txnNumber : number ; isDirty : boolean } | null
975
+ ) {
976
+ if ( cloned != null ) {
977
+ const idBytes = Buffer . allocUnsafe ( 16 ) ;
978
+ idBytes . set ( cloned . id . id . buffer ) ;
979
+ this . id = { id : new Binary ( idBytes , cloned . id . id . sub_type ) } ;
980
+ this . lastUse = cloned . lastUse ;
981
+ this . txnNumber = cloned . txnNumber ;
982
+ this . isDirty = cloned . isDirty ;
983
+ return ;
984
+ }
977
985
this . id = { id : new Binary ( uuidV4 ( ) , Binary . SUBTYPE_UUID ) } ;
978
986
this . lastUse = now ( ) ;
979
987
this . txnNumber = 0 ;
@@ -994,30 +1002,6 @@ export class ServerSession {
994
1002
995
1003
return idleTimeMinutes > sessionTimeoutMinutes - 1 ;
996
1004
}
997
-
998
- /**
999
- * @internal
1000
- * Cloning meant to keep a readable reference to the server session data
1001
- * after ClientSession has ended
1002
- */
1003
- static clone ( serverSession : ServerSession ) : Readonly < ServerSession > {
1004
- const arrayBuffer = new ArrayBuffer ( 16 ) ;
1005
- const idBytes = Buffer . from ( arrayBuffer ) ;
1006
- idBytes . set ( serverSession . id . id . buffer ) ;
1007
-
1008
- const id = new Binary ( idBytes , serverSession . id . id . sub_type ) ;
1009
-
1010
- // Manual prototype construction to avoid modifying the constructor of this class
1011
- return Object . setPrototypeOf (
1012
- {
1013
- id : { id } ,
1014
- lastUse : serverSession . lastUse ,
1015
- txnNumber : serverSession . txnNumber ,
1016
- isDirty : serverSession . isDirty
1017
- } ,
1018
- ServerSession . prototype
1019
- ) ;
1020
- }
1021
1005
}
1022
1006
1023
1007
/**
0 commit comments