percy / cli

The Percy CLI is used to interact with, and upload snapshots to, percy.io via the command line.
https://docs.percy.io/docs/cli-overview
70 stars 43 forks source link

percy snapshot hanging when finalizing the snaphsots #742

Closed cancan101 closed 2 years ago

cancan101 commented 2 years ago

The problem

Reposting from https://github.com/percy/cli/issues/735#issuecomment-1020399498:

Seems to be handing indefinitely after:

[percy:client] Uploading resource: /percy.1629232245XXX.log... (2ms)
[percy:client] Finalizing snapshot XXX784804... (323ms)
[percy:client] Finalizing snapshot XXX784803... (2ms)

It looks like the problem might be related to the execute.afterNavigation taking a while to execute.

This causes the issue:

afterNavigation: 'function sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms));};const sections = 12; for(var i = 1; i <=sections; i++){window.scrollTo({top: (document.body.scrollHeight/sections)*i, behavior: "smooth"}); await sleep(1000);} window.scrollTo(0, 0); await sleep(500);'

whereas this seems fine (change the sleep time from 1000 to 500):

afterNavigation: 'function sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms));};const sections = 12; for(var i = 1; i <=sections; i++){window.scrollTo({top: (document.body.scrollHeight/sections)*i, behavior: "smooth"}); await sleep(500);} window.scrollTo(0, 0); await sleep(500);'

Environment

Details

If necessary, describe the problem you have been experiencing in more detail.

Debug logs

Running with --verbose did not produce and more results.

wwilsman commented 2 years ago

Hey @cancan101! 👋

Logs starting with [percy:client] come from API communications. Those logs specifically come after a snapshot's resources are uploaded to the API. If the process is truly hanging there, execute hooks shouldn't have an effect since they are run before a snapshot is captured (therefore before being uploaded).

It could still be hanging because of the long waits, but those client logs don't seem to be relevant to how/where. Does it hang for a specific snapshot, any snapshot, or only when handling multiple snapshots? If you can narrow it down further and/or provide a reproduction so we can get a better look at the logs, that would help figure out if this is a regression or an edge case and how exactly we should address it.

cancan101 commented 2 years ago

Is there any possibility of a race, i.e. in the case that the execute for a given page / snapshot takes a very long time to run?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

bporcelli commented 2 years ago

Sorry if this is not helpful, but I had a similar issue with @percy/cypress and in my case the root cause was a Promise in one of my custom Cypress commands that was not being resolved. Cypress was just sitting and waiting for the bugged Promise to resolve while meanwhile the test had already completed and the snapshot had already been finalized.

Obviously this is not going to be the same exact issue, but I suspect the fundamentals may be the same, i.e. the runtime is waiting for some Promise to resolve and that's not happening. Curious what would happen if this execute.afterNavigation code was rewritten to not use Promises 🤔

bporcelli commented 2 years ago

Actually, it turns out the hang I was observing was not related to the way I was managing promises in my Cypress test code and it wound up resurfacing late last week.

In our case the problem seems to affect snapshots of a specific page template of which you can find a representative example here (note: this specific link may break if the MLS data changes, but you can find other examples on the /properties/ page). I'm having issues reproducing the hang locally on macOS with node 16 but I can consistently reproduce it in the GitHub Actions ubuntu-latest environment. Here's a repository with a basic reproducible test case: https://github.com/bporcelli/percy-hang-error

And here's an example of an actions run where the process seemed to hang after the "Finalizing snapshot..." message was logged: https://github.com/bporcelli/percy-hang-error/runs/5366359202

You can see that the process just got stuck there until the configured job timeout of 15m was eventually reached.

@wwilsman Any ideas what may be happening here? We're really excited about integrating Percy into our Cypress test suites but this is holding us up. Thanks in advance for your help!

bporcelli commented 2 years ago

@wwilsman Just wanted to follow up and see if you or someone else on the Percy team has had time to look into this issue. My last comment includes a reproducible test case that may help with your investigation. If you need any other information please let me know.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 28 days with no activity.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 28 days with no activity.

sigginjals commented 2 years ago

@Robdel12 or @bporcelli Did you guys solve this?, I'm experiencing the exact same issue...

bporcelli commented 2 years ago

@sigginjals I eventually discovered that this is an issue with Cypress (https://github.com/cypress-io/cypress/issues/8206). Switching the test browser from Electron to Chrome resolved the issue for my team. Tests have been running without hangs now for a couple months.