Skip to content

Commit

Permalink
Introduce environment variable to override connexion settings (#13936)
Browse files Browse the repository at this point in the history
fixes #13800

contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
Co-authored-by: Philip Langer <planger@eclipsesource.com>
  • Loading branch information
rschnekenbu and planger committed Jul 18, 2024
1 parent feeb791 commit 9e307dd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<!-- ## not yet released
- [core] introduce `FRONTEND_CONNECTION_TIMEOUT` environment variable to override application connexion settings. [#13936](https://github.com/eclipse-theia/theia/pull/13936) - Contributed on behalf of STMicroelectronics
<a name="breaking_changes_not_yet_released">[Breaking Changes:](#breaking_changes_not_yet_released)</a>
-->
Expand Down
4 changes: 4 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ Where `root` is the name of the logger and `INFO` is the log level. These are op
- If possible, you should set this environment variable:
- When not set, Theia will allow any origin to access the WebSocket services.
- When set, Theia will only allow the origins defined in this environment variable.
- `FRONTEND_CONNECTION_TIMEOUT`
- The duration in milliseconds during which the backend keeps the connection contexts for the frontend to reconnect.
- This duration defaults to '0' if not set.
- If set to negative number, the backend will never close the connection.

## Additional Information

Expand Down
4 changes: 4 additions & 0 deletions packages/core/README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Where `root` is the name of the logger and `INFO` is the log level. These are op
- If possible, you should set this environment variable:
- When not set, Theia will allow any origin to access the WebSocket services.
- When set, Theia will only allow the origins defined in this environment variable.
- `FRONTEND_CONNECTION_TIMEOUT`
- The duration in milliseconds during which the backend keeps the connection contexts for the frontend to reconnect.
- This duration defaults to '0' if not set.
- If set to negative number, the backend will never close the connection.

## Additional Information

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export class WebsocketFrontendConnectionService implements FrontendConnectionSer
socket.on('disconnect', evt => {
console.info('socked closed');
channel.disconnect();
const timeout = BackendApplicationConfigProvider.get().frontendConnectionTimeout;

const timeout = this.frontendConnectionTimeout();
const isMarkedForClose = this.channelsMarkedForClose.delete(frontEndId);
if (timeout === 0 || isMarkedForClose) {
this.closeConnection(frontEndId, evt);
Expand All @@ -124,6 +125,15 @@ export class WebsocketFrontendConnectionService implements FrontendConnectionSer
markForClose(channelId: string): void {
this.channelsMarkedForClose.add(channelId);
}

private frontendConnectionTimeout(): number {
const envValue = Number(process.env['FRONTEND_CONNECTION_TIMEOUT']);
if (!isNaN(envValue)) {
return envValue;
}

return BackendApplicationConfigProvider.get().frontendConnectionTimeout;
}
}

class ReconnectableSocketChannel extends AbstractChannel {
Expand Down

0 comments on commit 9e307dd

Please sign in to comment.