Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

tshd-initiated communication for Connect#1176

Closed
ravicious wants to merge 2 commits intomasterfrom
ravicious/tshd-initiated-comm
Closed

tshd-initiated communication for Connect#1176
ravicious wants to merge 2 commits intomasterfrom
ravicious/tshd-initiated-comm

Conversation

@ravicious
Copy link
Copy Markdown
Member

@ravicious ravicious commented Sep 1, 2022

teleport counterpart: gravitational/teleport#16043

The important logic is contained within ClustersService.initializeClusterEventsStream which I plan to refactor to a separate service.

That method is called from AppContext.init when the app starts.

// TODO: Move this elsewhere, perhaps ClusterEventsService?
async initializeClusterEventsStream() {
const uid = unique(5);
const logger = new Logger(`Cluster events ${uid}`);
logger.info('Initializing cluster events stream');
const clusterEventsStream = this.client.clusterEvents();
clusterEventsStream.onNewGatewayConnectionAccepted(() => {
logger.info('New connection accepted!');
});
clusterEventsStream.onError((error: Error) => {
// TODO: Add gRPC stream interceptor in lib/teleterm/apiserver so that error codes are
// properly propagated. Then match on AlreadyExists code rather than the error message.
if (error.message.includes('another stream is already active')) {
logger.error('Another cluster events stream is already open!');
return;
}
logger.error(
`Restarting cluster events stream because of an error`,
error
);
this.initializeClusterEventsStream();
});
clusterEventsStream.onEnd(() => {
logger.info('Cluster events stream has been closed by the server');
});
clusterEventsStream.onStatus(status => {
logger.info(
'Cluster events stream received status from the server',
status
);
});
}

async init(): Promise<void> {
// The stream for cluster events needs to be initialized first, otherwise the code in tshd that
// writes to it will block execution.
// TODO: Expand the comment above.
await this.clustersService.initializeClusterEventsStream();
await this.clustersService.syncRootClusters();
this.workspacesService.restorePersistedState();
}

Updates gravitational/webapps.e#299

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant