You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rpc: a peer client is unreachable after it reconnects #761
After the server drops a peer client's connection and the client reconnects, calls to its peer id never settle, and calling registerAsPeer again fails with "Already registered as a peer".
import{DirectClient,rpc,RpcKernel,RpcKernelBaseConnection,RpcKernelSecurity}from'@deepkit/rpc';classPeerSecurityextendsRpcKernelSecurity{asyncisAllowedToSendToPeer(){returntrue;}asyncisAllowedToRegisterAsPeer(){returntrue;}}classWorkerController{
@rpc.action()work(job: string): string{returnjob+' done';}}constkernel=newRpcKernel([{provide: RpcKernelSecurity,useClass: PeerSecurity,scope: 'rpc'}]);constserverConnections: RpcKernelBaseConnection[]=[];kernel.onConnection(connection=>serverConnections.push(connection));constworker=newDirectClient(kernel);awaitworker.registerAsPeer('mail-worker');worker.registerPeerController(WorkerController,'worker');constcaller=newDirectClient(kernel);constworkerApi=caller.peer('mail-worker').controller<WorkerController>('worker');console.log(awaitworkerApi.work('send'));// 'send done'// the server drops the worker's connection (restart, load balancer, network), the worker reconnectsserverConnections[0].close();awaitnewPromise(resolve=>setTimeout(resolve,20));awaitworker.connect();constafterOneSecond=newPromise(resolve=>setTimeout(()=>resolve('pending after 1 s'),1000));console.log(awaitPromise.race([workerApi.work('send'),afterOneSecond]));// actual: 'pending after 1 s', should be: 'send done'console.log(awaitworker.registerAsPeer('mail-worker').then(()=>'registered',(error: Error)=>error.message));// actual: 'Already registered as a peer', should be: 'registered'
Related: #760 (the peer id stays registered after the client disconnects).
Activity