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

Race condition between util.exec and cloud.Website #5608

Open
skyrpex opened this issue Feb 2, 2024 · 1 comment
Open

Race condition between util.exec and cloud.Website #5608

skyrpex opened this issue Feb 2, 2024 · 1 comment
Labels
🐛 bug Something isn't working 🎨 sdk SDK

Comments

@skyrpex
Copy link
Contributor

skyrpex commented Feb 2, 2024

I tried this:

Run wing compile main.w -t tf-aws on this file:

bring util;
bring cloud;

pub struct ViteProps {
  root: str;
  env: Map<str>?;
}

class ViteTfAws {
  pub url: str;

  new(props: ViteProps) {
    // This command generates a `{props.root}/dist/` directory.
    util.exec(
      "pnpm",
      ["vite", "build"],
      cwd: props.root,
      inheritEnv: true,
      env: props.env,
    );

    // Runs a `scandir` on `{props.root}/dist` (before it exists...).
    let website = new cloud.Website(
      path: "{props.root}/dist",
    );
    this.url = website.url;
  }
}

new ViteTfAws(
  root: "../website",
);

This happened:

runtime error: ENOENT: no such file or directory, scandir '/Users/cristian/Code/website/dist'
   --> vite.w:88:19
   |   env: props.env,
   | );
   | 
88 | let website = new cloud.Website(

I expected this:

The exec command creates the directory, but seems to be run after the Website resource is instantiated.

Both exec and shell utils return a promise, which isn't awaited by the resource preflight constructor.

Is there a workaround?

You can create your own spawnSync-like extern:

const child_process = require("node:child_process");

exports.spawnSync = (options) => {
  child_process.spawnSync(options.command, options.arguments, {
    cwd: options.cwd,
    env: options.env,
    stdio: "inherit",
  });
};

Anything else?

No response

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@skyrpex skyrpex added the 🐛 bug Something isn't working label Feb 2, 2024
@Chriscbr
Copy link
Contributor

Chriscbr commented Feb 7, 2024

Related #5425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎨 sdk SDK
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

3 participants