Skip to content

Various prebuild fixes #20057

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

Merged
merged 11 commits into from
Jul 24, 2024
Merged

Various prebuild fixes #20057

merged 11 commits into from
Jul 24, 2024

Conversation

filiptronicek
Copy link
Member

@filiptronicek filiptronicek commented Jul 22, 2024

Description

This PR fixes a couple of prebuilds-related issues. It originally was set out to fix incomplete endings of logs, but it ended up being about so a couple of other fixes, just not about this one 🤷.

Related Issue(s)

Fixes ENT-445
Fixes the NetworkError when attempting to fetch resource bug

How to test

  1. Try executing some prebuild
  2. Optionally, also try to run a failed prebuild (for instance https://github.com/mustard-mh/test/tree/prebuild/image-build-failed) and observe it in real time for ENT-445.

https://ft-fix-suc3e31a702ac.preview.gitpod-dev.com

console.debug("fetching from streamUrl: " + streamUrl);
response = await fetch(streamUrl, {
method: "GET",
cache: "no-cache",
Copy link
Member Author

Choose a reason for hiding this comment

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

using no-cache here might've been problematic, because the browser makes a conditional request in the case there is a cache entry present for this request. The problem is that no-cache actually does cache 🙃


const decoder = new TextDecoder("utf-8");
let chunk = await reader.read();
while (!chunk.done) {
if (disposables.disposed) {
// stop reading when disposed
Copy link
Member Author

Choose a reason for hiding this comment

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

this means we don't have to read the whole body anymore if we dispose in the midst of it.

@@ -860,6 +860,12 @@ export class WorkspaceStarter {
type: HeadlessWorkspaceEventType.Failed,
workspaceID: workspace.id,
});
await this.publisher.publishPrebuildUpdate({
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes ENT-445

go func(t *task, term *terminal.Term) {
state, err := term.Wait()
taskLog.Info("task terminal has been closed. Waiting for watch() to finish...")
taskWatchWg.Wait()
Copy link
Member Author

Choose a reason for hiding this comment

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

this makes sure that we append the 🍊 line before actually stopping the task.

Copy link
Member Author

@filiptronicek filiptronicek Jul 23, 2024

Choose a reason for hiding this comment

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

There might be a case we're missing here:

n, err := reader.Read(buf)
if err == io.EOF {
if isClosed.Load() {
// We are done
log.Println("[prebuildlog]: closing because task state is done and we are done reading")
return nil
}
}

Imagine that the task was just closed, and we have also just encountered the end of the file, but in the meantime by finishing it has written the last 🍊 line to the output, which we now didn't catch.

From the logs, the difference in a sample prebuild I did between setting the task state to closed and us closing the stream off is about 0.3 milliseconds, but I do not know on which timescale the file watcher operates.

Edit: from a quick test, it turns out that between writing to a file and getting a notification for it, it takes approximately 0.2ms, so maybe we're just too slow with the final notification.

Copy link
Member

Choose a reason for hiding this comment

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

I think you are spot on. I tried to come up with a patch for it. @filiptronicek Is it fine if I add that on top of your PR?

Make sure we wait for the line to be written first
@filiptronicek filiptronicek changed the title Fix incomplete prebuild logs Various prebuild fixes Jul 23, 2024
@filiptronicek
Copy link
Member Author

Here are the logs from my latest experiment with 4 clients: (could come in handy in the future)

{
  "alias": "505309c5-e312-4544-aa90-1bbcb319ecf8",
  "file": "terminal.go:139",
  "func": "doClose",
  "level": "info",
  "message": "closing terminal",
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "time": "2024-07-23T12:55:12.790276055Z"
}
{
  "file": "export.go:84",
  "func": "Error",
  "level": "error",
  "message": "Added kumquat line to prebuild log",
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "ERROR",
  "time": "2024-07-23T12:55:12.790467795Z"
}
{
  "command": "{\n./mvnw clean install -U -DskipTests\n}; exit",
  "file": "tasks.go:330",
  "func": "func2",
  "level": "info",
  "message": "task terminal has been closed. Waiting for watch() to finish...",
  "pid": 58,
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "terminal": "505309c5-e312-4544-aa90-1bbcb319ecf8",
  "time": "2024-07-23T12:55:12.790385835Z"
}
{
  "command": "{\n./mvnw clean install -U -DskipTests\n}; exit",
  "file": "tasks.go:332",
  "func": "func2",
  "level": "info",
  "message": "watch() has finished, setting task state to closed",
  "pid": 58,
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "terminal": "505309c5-e312-4544-aa90-1bbcb319ecf8",
  "time": "2024-07-23T12:55:12.790609845Z"
}
{
  "file": "export.go:154",
  "func": "Println",
  "level": "info",
  "message": "[prebuildlog]: closing because task state is done and we are done reading",
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "time": "2024-07-23T12:55:12.790782805Z"
}
{
  "file": "export.go:154",
  "func": "Println",
  "level": "info",
  "message": "[prebuildlog]: closing because task state is done and we are done reading",
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "time": "2024-07-23T12:55:12.790780865Z"
}
{
  "file": "export.go:154",
  "func": "Println",
  "level": "info",
  "message": "[prebuildlog]: closing because task state is done and we are done reading",
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "time": "2024-07-23T12:55:12.790816395Z"
}
{
  "file": "export.go:154",
  "func": "Println",
  "level": "info",
  "message": "[prebuildlog]: closing because task state is done and we are done reading",
  "serviceContext": {
    "service": "supervisor",
    "version": "commit-c275510fe58b6865ae5f5b10b85cd00a06ffc908-632948a1a049dce65aa5e2f57ce4cd64b2cb36be"
  },
  "severity": "INFO",
  "time": "2024-07-23T12:55:12.790802255Z"
}

@filiptronicek
Copy link
Member Author

I'm going to re-create the preview environment, as it's been GC'd over night.

@geropl
Copy link
Member

geropl commented Jul 24, 2024

@filiptronicek Taking a closer look now.

@geropl
Copy link
Member

geropl commented Jul 24, 2024

image ❤️

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested and works nicely, thanks! 🙏 ✔️

@roboquat roboquat merged commit 10810ce into main Jul 24, 2024
19 checks passed
@roboquat roboquat deleted the ft/fix-success-message-races branch July 24, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants