Skip to content

Commit

Permalink
update following upstream Theia changes
Browse files Browse the repository at this point in the history
There were some recent Theia changes[1] that required to change the way our
Theia extension starts. It used to be that our TraceServerUrlProviderImpl
backend contribution could wait in the "initialize" Theia app life-cucle
phase, until the application was started and it received the trace server
port from the front-end, from our PreferencesFrontendContribution.

But the above no longer works. Now backend contributions are started in
parallel, and all are expected to finish their initialize phase, before the
"start" phase is initiated.

In practice, after upgrading to Theia v1.45.1, the Theia application, that
includes the trace viewer extension,  would be killed during startup, with
no clear indication why.

To prevent this from happening, the need to receive information from the
front-end has been removed: the backend contribution will now initialize
with the assumption that the default trace server port is used. If a
different port was configured in the preferences, the information will be
synched after the app has started.

[1]: eclipse-theia/theia#12818

specifically:

"The BackendApplicatinContribution init and configure methods are now called
in parallel for all contributions instead of sequentially."

Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
  • Loading branch information
marcdumais-work committed Feb 28, 2024
1 parent ad4ad78 commit d0532ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
import { inject, injectable } from 'inversify';
import { PortPreferenceProxy } from '../common/trace-server-url-provider';
import { PortPreferenceProxy, TRACE_VIEWER_DEFAULT_PORT } from '../common/trace-server-url-provider';
import { TracePreferences, TRACE_PORT } from './trace-server-preference';

@injectable()
Expand All @@ -12,7 +12,15 @@ export class PreferencesFrontendContribution implements FrontendApplicationContr

async initialize(): Promise<void> {
this.tracePreferences.ready.then(() => {
this.portPreferenceProxy.onPortPreferenceChanged(this.tracePreferences[TRACE_PORT]);
// assume the backend starts with the default server port - if the user configured
// a different port in the preferences, tell backend to change it
const tracePortPref = this.tracePreferences[TRACE_PORT];
if (tracePortPref === TRACE_VIEWER_DEFAULT_PORT) {
this.portPreferenceProxy.onPortPreferenceChanged(tracePortPref);
} else {
this.portPreferenceProxy.onPortPreferenceChanged(tracePortPref, TRACE_VIEWER_DEFAULT_PORT, true);
}

this.tracePreferences.onPreferenceChanged(async event => {
if (event.preferenceName === TRACE_PORT) {
const newValue = typeof event.newValue === 'string' ? parseInt(event.newValue) : event.newValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TraceServerConfigService } from '../common/trace-server-config';
import {
TraceServerUrlProvider,
TRACE_SERVER_DEFAULT_URL,
TRACE_VIEWER_DEFAULT_PORT,
PortPreferenceProxy
} from '../common/trace-server-url-provider';
import { Event, Emitter } from '@theia/core';
Expand Down Expand Up @@ -59,6 +60,7 @@ export class TraceServerUrlProviderImpl
// Get the URL template from the remote environment.
const variable = process.env['TRACE_SERVER_URL'];
this._traceServerUrlTemplate = variable ? this.normalizeUrl(variable) : TRACE_SERVER_DEFAULT_URL;
this._traceServerPort = TRACE_VIEWER_DEFAULT_PORT;
this.updateTraceServerUrl();
}

Expand All @@ -69,7 +71,8 @@ export class TraceServerUrlProviderImpl
): Promise<void> {
this._traceServerPort = newPort;
this.updateTraceServerUrl();
if (preferenceChanged) {

if (preferenceChanged || this._traceServerPort !== newPort) {
try {
await this.traceServerConfigService.stopTraceServer();
if (oldValue) {
Expand All @@ -82,7 +85,8 @@ export class TraceServerUrlProviderImpl
}

async initialize(): Promise<void> {
// Don't start the application until the Trace Server URL is initialized.
// Don't conclude the initialization life-cycle phase of this contribution
// until the Trace Server URL is initialized.
await this._traceServerUrlPromise;
}

Expand Down

0 comments on commit d0532ff

Please sign in to comment.