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

[Bug]: shopify app dev stops authenticating development store preview #3173

Closed
2 tasks done
awd opened this issue Dec 5, 2023 · 15 comments · Fixed by #3181 or #3375
Closed
2 tasks done

[Bug]: shopify app dev stops authenticating development store preview #3173

awd opened this issue Dec 5, 2023 · 15 comments · Fixed by #3181 or #3375
Labels
Type: Bug Something isn't working

Comments

@awd
Copy link
Contributor

awd commented Dec 5, 2023

Please confirm that you have:

  • Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

App

Expected behavior

Running shopify app dev should be a simple task, but it fails frequently when using it in.

Something is causing the draft previews to update, and the error below appears in red text.

Actual behavior

After some time, and usually quitting and re-running shopify app dev the error message does not appear.

When this message appears it means draft versions of app extensions, checkout extensions, theme extensions fail to update as well. It's a huge pain because it means extra steps to continuing to work. It breaks the flow when suddenly the extension is not responding to code changes (did I introduce a bug?, did I break something?)

Verbose output

Failed to fetch the latest status of the development store preview, trying again in 5 seconds.

This error appears in RED text in the console.



### Reproduction steps

1. run `shopify app dev`
2. sometimes the error happens, which needs a full quit and restart

### Operating System

OSX

### Shopify CLI version (check your project's `package.json` if you're not sure)

latest

### Shell

iterm2

### Node version (run `node -v` if you're not sure)

latest

### What language and version are you using in your application?

latest
@awd awd added the Type: Bug Something isn't working label Dec 5, 2023
@amcaplan
Copy link
Contributor

amcaplan commented Dec 6, 2023

Hi @awd, I think the development store preview message is a red herring. That's a polling check for whether development store preview is enabled or disabled, but it has nothing to do with pushing your extensions.

It sounds, though, like it happens at the same time that draft-pushing stops. Which means there's some kind of authentication issue (e.g. the token expired) and CLI requires a restart, but can't prompt you to reauthenticate mid-dev. It might even be best to crash at that point vs. continuing to run but not being fully functional.

It would definitely help to run in --verbose mode and see any details on the error, but there will be huge amounts of text to sort through. So it's probably best if you can indicate a minimal repro, or at the very least any steps that would make this issue more likely to happen, so we can investigate more fully. Is it just a matter of waiting long enough?

@awd
Copy link
Contributor Author

awd commented Dec 6, 2023

Hey @amcaplan

Thanks for replying so quickly on this one. I think crashing out might be useful here, because it does seem like the draft is no longer pushing.

I've started running with --verbose to try and catch it in action, and see if there are steps to reproduce.

Typically I'll run the command (first time for the day), and then it'll fail within a few minutes. Then I re-run the command, and it tends to work much longer. Not always the case, but seems like the first run after some time period of not running the command - causes it. Like there is an old token with a 5 min TTL or something cached in the tool.

If I notice anything through --verbose I'll update here again as well.

@awd
Copy link
Contributor Author

awd commented Dec 7, 2023

Hi again @amcaplan

Here's a snippet of verbose output when the red message appears.
This will continue to retry every 5s.

2023-12-07T16:16:28.594Z: Sending "Partners" GraphQL request:
  query FindAppPreviewMode($apiKey: String!) {
    app(apiKey: $apiKey) {
      developmentStorePreviewEnabled
    }
  }

With variables:
{
  "apiKey": "*****"
}

With request headers:
 - User-Agent: Shopify CLI; v=3.50.2
 - Keep-Alive: timeout=30
 - Sec-CH-UA-PLATFORM: darwin
 - Content-Type: application/json

2023-12-07T16:16:28.921Z: Request to https://partners.shopify.com/api/cli/graphql completed in 325 ms
With response headers:
 - cache-control: no-cache
 - content-type: text/html
 - x-request-id: 144d6631-8f33-4c36-8519-f5e864fc726e

Here's a few more request-ids:
x-request-id: 85e23137-8bbf-473f-94a3-f14ae21d8e6e
x-request-id: 32a828b7-196e-4820-8edc-30ea01b92b9a
x-request-id: df4ff49e-8886-429b-8c2d-0c2d36199f31

It basically continues to poll and the red message never clears, and pushing draft extension code silently stops.

When I modify extension code, and the push is attempted this is the output:

Please provide this information with your report:
www-authenticate: Bearer realm="******",error="invalid_token",error_description="The access token provided is expired, revoked,
malformed, or invalid for other reasons."
x-request-id: bc8751f7-3975-4e90-a13d-cfe6d2c60f61

Keep in mind this isn't always happening, but once it starts. I need to fully quit the process and rerun the original command. This tells me the token is not invalid (or should not be at least).

@amcaplan
Copy link
Contributor

amcaplan commented Dec 7, 2023

@awd there's supposed to be a mechanism to refresh authentication in the background, which might be failing. Do you see in the verbose output anywhere: Failed to refresh token?

@awd
Copy link
Contributor Author

awd commented Jan 4, 2024

Hey @amcaplan

Yep, the log output is below. Im experiencing this very frequently now, and have updated to the latest 3.53.0 release as well.

--verbose:

09:56:02 │ extensions   │ Please provide this information with your report:
09:56:02 │ extensions   │ www-authenticate: Bearer realm="***",error="invalid_token",error_description="The access token provided is expired, revoked,
malformed, or invalid for other reasons."
09:56:02 │ extensions   │ x-request-id: 0344526a-4004-462a-a143-5a91e1179df8
09:56:02 │ extensions   │

Sometimes the CLI will report the auth has failed, and other times it's silent. Once I kill the process then I'll see the output that the auth has failed. Not sure how to reproduce this, seems like network conditions are at play?

The only way I can resolve it is to quit the process entirely, and restart it.

@amcaplan
Copy link
Contributor

amcaplan commented Jan 4, 2024

Thanks @awd! I'm surprised you're still seeing the issue on 3.53. With recent work, we should be detecting failure to refresh the token and completely erroring out.

I can try digging into that request ID and figuring out what happened.

@amcaplan amcaplan reopened this Jan 4, 2024
@amcaplan
Copy link
Contributor

amcaplan commented Jan 7, 2024

@awd I haven't really found any answers yet. The CLI should refresh the token in the background, but there are certain circumstances where it fails to do so, such as if you've logged out in the browser. Is it possible that that's happening?

@awd
Copy link
Contributor Author

awd commented Jan 9, 2024

Totally understand, It's definitely strange..

Im logged into the browser, in my dev store, in the partner dashboard, etc. All seems to be fine.

The auth appears to fail a lot - my network is stable (Starlink), wonder why are the auth tokens so short lived? Seems like every 2-5 minutes they are expired.

This is occurs specifically when working on theme extensions, where code changes are pushing to development store preview - draft themes.

When a local code change occurs, this appears in the CLI console:
14:17:45 │ extensions │ Pushed » 'theme-extension' to a draft

Then when the auth has failed - nothing happens after saving a code change.

Just trying to provide more info to see if something rings a bell. I appreciate the help here, it's one of those things that adds a few extra steps every couple of minutes, and confusing when silently failed as my code change isn't reflected in the draft theme editor.

@scerelli
Copy link

Totally understand, It's definitely strange..

Im logged into the browser, in my dev store, in the partner dashboard, etc. All seems to be fine.

The auth appears to fail a lot - my network is stable (Starlink), wonder why are the auth tokens so short lived? Seems like every 2-5 minutes they are expired.

This is occurs specifically when working on theme extensions, where code changes are pushing to development store preview - draft themes.

When a local code change occurs, this appears in the CLI console: 14:17:45 │ extensions │ Pushed » 'theme-extension' to a draft

Then when the auth has failed - nothing happens after saving a code change.

Just trying to provide more info to see if something rings a bell. I appreciate the help here, it's one of those things that adds a few extra steps every couple of minutes, and confusing when silently failed as my code change isn't reflected in the draft theme editor.

@awd I'm in the exact situation. I push changes for few minutes on my theme app extension and then suddenly it stops authenticating my changes and i have to kill the dev process and start it again.

It's really frustrating as i also need to reconfigure the dev theme, linked to my theme app extension, every time i restart dev because it doesn't keep my configurations.

@thesunilyadav
Copy link

Encountering a similar problem as described by the user @awd

@amcaplan
Copy link
Contributor

Hey folks, I recognize this took some time to figure out, but I have a repro, and this is definitely specific to theme app extensions. I have traced the root cause of the problem, made a potential fix, and am in the process of verifying.

On another note, @scerelli I wanted to ask you about this:

It's really frustrating as i also need to reconfigure the dev theme, linked to my theme app extension, every time i restart dev because it doesn't keep my configurations.

Can you please elaborate more on what you mean when you say "it doesn't keep my configurations"? This sounds like useful feedback that we'd love to know more about.

@scerelli
Copy link

@amcaplan I'm experiencing a problem where my session token expires every ~10 minutes. This requires me to restart the development process, to get a new one. Meanwhile, I have set up various theme app extensions and configurations in the theme editor (from the link provided in the terminal). However, each time I restart the dev process, the configurations in the theme editor revert to the default 'Dawn' settings, so every time i restart it i got to reconfigure the theme from scratch. I thought about using theme pull to solve this, but I'm not sure how to proceed since the theme provided by the dev process isn't in the project.

@amcaplan
Copy link
Contributor

amcaplan commented Feb 4, 2024

Just a quick ping, been a bit busy with Winter Edition (check it out if you haven't yet!) but I've also had some challenges getting the fix to work reliably. I want to fix this right, which may take a bit more time.

Anyway, just didn't want you all thinking I'd forgotten you.

@amcaplan amcaplan mentioned this issue Feb 5, 2024
6 tasks
@jriemann
Copy link

jriemann commented Feb 6, 2024

Thanks @amcaplan !

@amcaplan
Copy link
Contributor

amcaplan commented Feb 8, 2024

Hey folks! By now the latest changes should be included in the nightly release of the CLI. So if you update your @shopify/app and @shopify/cli to point to the nightly tag in your app's package.json, you should be able to test out the changes and let us know if your problem has been solved.

The updates will of course also be included in the 3.56.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants