Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor+fix trace server url initialization #502

Merged
merged 13 commits into from
Sep 27, 2021

Conversation

paul-marechal
Copy link
Member

@paul-marechal paul-marechal commented Sep 23, 2021

Both TraceServerUrlProviderImpl and TraceViewerEnvironment are
riddled with concurrency issues. A lot of events happen asynchronously
but the logic doesn't take this into account, leaving the application
vulnerable to race conditions when trying to fetch the trace server url.

Refactor by removing TraceViewerEnvironment and moving its
functionality directly into TraceServerUrlProviderImpl, add logic to
prevent race conditions.

Unfortunately I was forced to introduce a LazyTspClient which is
implemented as a proxy to a TspClient and defers all async method
calls until baseUrl is asynchronously resolved. This only works because
all TspClient methods are asynchronous.

The proxy is a temporary measure which should buy you time until
you guys rework the frontend initialization sequence to make sure
everyone expects and handles the asynchronous steps.

Fixes #493
Closes #499

@paul-marechal
Copy link
Member Author

paul-marechal commented Sep 23, 2021

Some notes about the use of the LazyTspClient: classes seem to want to synchronously get a reference to a TspClient, but all work done through it is asynchronous. All places that uses the TspClient deal with asynchronous calls. This makes me think that it should be possible to instead pass around a promise to a TspClient and first await on this before using its async methods. We're dealing with async stuff anyway when it gets time to use it.

Copy link
Collaborator

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me and it works locally and in GitPod. Thanks for improvement! @paul-marechal, could you please answer my question.

packages/base/src/lazy-tsp-client.ts Show resolved Hide resolved
packages/base/src/lazy-tsp-client.ts Outdated Show resolved Hide resolved
packages/base/src/lazy-tsp-client.ts Outdated Show resolved Hide resolved
@paul-marechal paul-marechal force-pushed the trace-url-env-fix branch 4 times, most recently from 7ed41a4 to 9c8bea5 Compare September 24, 2021 18:09
@paul-marechal
Copy link
Member Author

PR is good for re-review/merging again!

bhufmann
bhufmann previously approved these changes Sep 24, 2021
Copy link
Collaborator

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it locally (with default URL) and in GitPod where a custom URL via the TRACE_SERVER_URL environment variable is used. Both work well. Thanks for the contribution.

Both `TraceServerUrlProviderImpl` and `TraceViewerEnvironment` are
riddled with concurrency issues. A lot of events happen asynchronously
but the logic doesn't take this into account, leaving the application
vulnerable to race conditions when trying to fetch the trace server url.

Refactor by removing `TraceViewerEnvironment` and moving its
functionality directly into `TraceServerUrlProviderImpl`, add logic to
prevent race conditions.

Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
PatrickTasse
PatrickTasse previously approved these changes Sep 24, 2021
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
PatrickTasse
PatrickTasse previously approved these changes Sep 24, 2021
Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
PatrickTasse
PatrickTasse previously approved these changes Sep 24, 2021
@paul-marechal
Copy link
Member Author

Ok I am ashamed of continuously removing your approvals but this wasn't just nitpicking.

The value returned by getTraceServerUrlPromise() used to be set once, and any subsequent call would only ever return the initial value. This is now fixed.

Thanks for bearing with me!

Copy link
Collaborator

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now I found something :-) Could you please update it?

Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Copy link
Collaborator

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalizeUrl() method change in one of the previous commits causes that it won't work in GitPod anymore. See comment and suggestion below.

@ebugden
Copy link
Contributor

ebugden commented Sep 27, 2021

Thank you all for working on this! 🌳

Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Copy link
Collaborator

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the contribution.

@bhufmann bhufmann merged commit 3e9eb1b into eclipse-cdt-cloud:master Sep 27, 2021
@paul-marechal paul-marechal deleted the trace-url-env-fix branch September 27, 2021 18:22
hriday-panchasara pushed a commit to hriday-panchasara/theia-trace-extension that referenced this pull request Nov 10, 2021
Both `TraceServerUrlProviderImpl` and `TraceViewerEnvironment` are
riddled with concurrency issues. A lot of events happen asynchronously
but the logic doesn't take this into account, leaving the application
vulnerable to race conditions when trying to fetch the trace server url.

Refactor by removing `TraceViewerEnvironment` and moving its
functionality directly into `TraceServerUrlProviderImpl`, add logic to
prevent race conditions.

Signed-off-by: Paul Marechal <paul.marechal@ericsson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitPod not able to connect to GitPod trace server but connects to localhost server
4 participants