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

Intermitent parse error trailing garbage error #597

Open
profandyfield opened this issue Oct 13, 2021 · 21 comments
Open

Intermitent parse error trailing garbage error #597

profandyfield opened this issue Oct 13, 2021 · 21 comments

Comments

@profandyfield
Copy link

I'm using a package of learnr tutorials for teaching that I wrote (https://github.com/profandyfield/discovr ).

Some students intermitently get the following error when the click 'start tutorial'.

Error: parse error: trailing garbage

          ":{},"value":["0.10.1"]}]}]} {"type":"list","attributes":{},

                     (right here) ------^

Execution halted

I had similar issues last year as well which remained unresolved. I can't post a reporducible example because we can't reporduce it: We can't see any consistent predictors of when it happens or for whom. It feels impossible to debug but I also don't really understand the process of what happens when someone clicks the 'start tutorial' button (other than it reneders my RMD into a tutortial ... or how it uses a stored html file when a tutorial starts or how a stored html might become corrupt.

We have students who, for example, load a tutorial successfully using the RStudio tutorials pane, but then next time they load it they get this error. Based on my explorations last year I assume it's an error with the html renedering. Consistent with this assumption if we (a) manually delete the html of the problematic tutorial from the package library on their system, or (b) force a reinstall (which would also clear the html files) the problem goes away. However, it can return (for the same student).

I don't know if this is a bug, and I appreciate (really I do having tried to workiit out for over a year) how impossible it is to have a solution when we can't reliably reproduce the issue, but I would really appreciate some pointers about why this might be happening - like, some options to explore or some better understanding of the rendering process and why it might fail when it has succeeded before. Could this be down to user input in a previous session using the tutorial? Could it be to do with strange text in my hints? Is there something I can do within the tutorial to prevent it (I currently don't error catch any code that students type into exercises). Any useful pointers?

@gadenbuie
Copy link
Member

@gadenbuie
Copy link
Member

gadenbuie commented Oct 13, 2021

From "value":["0.10.1"] I'm guessing that this student has learnr version 0.10.1 installed (the current version on CRAN). An easy first place to start would be to find out if the problem goes away when students use the latest version of learnr from GitHub. Beyond that, it would be helpful to know which version of rmarkdown is in use; that error likely comes from rmarkdown's shiny prerendered dependency resolution. If rmarkdown is out of date, it may be a bug that has since been fixed. In short, if you could ask the students to capture their session info using devtools::session_info() when the error occurs, that could provide some important initial clues.

@profandyfield
Copy link
Author

It's miltiple students. We tell students to update to the lastest Rstudio (which should update Markdown shouldn't it?), so that's what they should be running. Anbd yes, they'd have the latest learnr from CRAN because we can't build from source in university computer labs (at least not easily) so we have to try to stick with CRAN packages. I can ask my tutors to get sessionInfo() when this happens again. If it is down to rmarkdown's shiny prerendered dependency resolution, is there a way I could test that by breaking it myself - could you give me an example of something that would break the tutorial so I can try to do that and report back more specific information?

@gadenbuie
Copy link
Member

Yes, asking for sesionInfo() would be a big help; without knowing specific package versions it's a very large haystack.

Another thing that could be helpful would be to send me the prerendered HTML file for the tutorial. When the error arises, you could ask the user (possibly with the tutor's help) to find the discovr_XX.html file and send it to you to share here.

# Navigate to the tutorial's folder in the RStudio Files pane
rstudioapi::filesPaneNavigate(
  system.file("tutorials", "discovr_XX", package = "discovr")
)

@bwagner
Copy link

bwagner commented Oct 20, 2021

Total newbie here. I consistently get the error when trying to run tutorial "Filter observations". Here's the output of sessionInfo():

R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin18.7.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /usr/local/Cellar/r/4.1.1_1/lib/R/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.1.1  fastmap_1.1.0   htmltools_0.5.2 tools_4.1.1    
 [5] yaml_2.2.1      rmarkdown_2.11  knitr_1.36      xfun_0.27      
 [9] digest_0.6.28   rlang_0.4.12    renv_0.14.0     evaluate_0.14  

In @gadenbuie 's suggestion, I didn't know what XX in disvovr_XX was supposed to be replaced with. (As mentioned above, the tutorial acting up was "Filter observations").

However, the problem disappeared after issuing remove.packages('learnr') and subsequently install.packages('learnr') in RStudio's Console.

@gadenbuie
Copy link
Member

In @gadenbuie 's suggestion, I didn't know what XX in disvovr_XX was supposed to be replaced with. (As mentioned above, the tutorial acting up was "Filter observations").

@bwagner The discovr_XX bit is relevant for the discovr package specifically, but you'd need something a little more general. For tutorials that are provided by packages, they must be installed in the "tutorials" folder of the package. You can find that folder using system.file():

system.file("tutorials", package = "learnr")
#> [1] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library/learnr/tutorials"

and then you can look in that folder to see the list of tutorials

dir(system.file("tutorials", package = "learnr"))
#>  [1] "ex-data-basics"    "ex-data-filter"    "ex-data-mutate"   
#>  [4] "ex-data-summarise" "ex-setup-r"        "hello"            
#>  [7] "polyglot"          "quiz_question"     "setup-chunks"     
#> [10] "slidy"

or find the folder for a specific tutorial

system.file("tutorials", "ex-data-filter", package = "learnr")
#> [1] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library/learnr/tutorials/ex-data-filter"

If you can reliably reproduce this issue with the Filter observations tutorial, would you mind following the steps above and sharing the .html file? Thanks!

@profandyfield
Copy link
Author

Yes, asking for sesionInfo() would be a big help; without knowing specific package versions it's a very large haystack.

Another thing that could be helpful would be to send me the prerendered HTML file for the tutorial. When the error arises, you could ask the user (possibly with the tutor's help) to find the discovr_XX.html file and send it to you to share here.

Attached is a zip file containing three recent cases. Each case I include the pre-renedered html file and the session info. I hope this is useful.
lexical_errors.zip

@profandyfield
Copy link
Author

added two more cases, case 5 includes 2 html files from sequential failures. Updated RStudio and it rendered after that
lexical_errors.zip
.

@eleanorbath
Copy link

Hi, @profandyfield, we had the same issue publishing to an RStudio Connect server (exact same error messages). Everything worked fine last year, but this year we couldn't publish anything (even ones that worked last year). We found that the issue was the latest version of RStudio that we were publishing from - if we downgraded from that, we didn't have the issues any more. Our errors popped up every time though, so I guess slightly different. Not sure if that's helpful, but you are not alone!

@profandyfield
Copy link
Author

we've been collecting some of these errors throughout term (this is not exhaustive by the way, just a selection of instances where we've been around to collect the failing html file and the session Info). There's now 15 cases (the first 5 cases are the same as those that I posted on Oct 22nd). I'm happy to keep stockpiling these if it's useful, but if it's not let me know and I'll stop
lexical_errors_2021_26.zip
!

@yassinza
Copy link

Hi @profandyfield , were you able to solve this? we are facing a similar issues on shinyapps. thanks!

@yassinza
Copy link

Hi @gadenbuie , me again :) We started facing this issue when we upgraded from free to the basic plan and started changing the setting for the app ( maybe not related, but worth mentioning).

We see this error happen after the app goes to sleep for some time and then we try to access it. any pointers on this, please? thanks!

image

@gadenbuie
Copy link
Member

Hi @yassinza – I've spent quite a while looking into this on many occasions. I have some theories, but the fact that I haven't been able to reliably reproduce it has been a major hinderance.

Would you be able to send me the .html version of your tutorial from the application bundle (or even just the whole bundle) the next time this happens? In the https://shinyapps.io dashboard, open your tutorial application and on the Overview page in the left column there's a button to download the Bundle. You can email me the archive or you can extract the .html file in it. My email is garrick@posit.co.

@gadenbuie
Copy link
Member

One thing that might work to help avoid this is to set the RMARKDOWN_RUN_PRERENDER environment variable to "1". This would, ideally, cause rmarkdown to re-render the tutorial anew every time it starts up. I recognize that's not ideal, but it seems that the issue occurs when the pre-rendered output of previously rendered tutorial is reused to speed up the app startup. In shinyapps.io, I believe you can deploy your app with an adjacent .Renviron with the entry

RMARKDOWN_RUN_PRERENDER=1

(If that does help, please let me know. That information will help isolate the bug.)

@gadenbuie
Copy link
Member

Hi all. Thank you very much to everyone in this thread for your help with this bug. In particular thank you @profandyfield and @yassinza for providing example files.

My apologies that this took so long to track down, but in returning to this issue with fresh eyes I found a new thread to pull and I think I understand why the bug is happening (but I still don't entirely know how this is happening).

In rstudio/rmarkdown#2499 I've outlined the mechanics of the bug as I understand it, and in rstudio/rmarkdown#2500 I've provided a work-around that at least avoids the crash on app startup. If you can try that PR, I'd appreciate it.

remotes::install_github("rstudio/rmarkdown#2500")

@yassinza
Copy link

yassinza commented Jul 21, 2023

Thanks a lot @gadenbuie!
I tried both:

  1. RMARKDOWN_RUN_PRERENDER=1 seems to work, but we keep seeing this error, but doesn't affect the app.

Error in shiny_prerendered_app(target_file, render_args = render_args) : 2023-07-20T16:31:19.021772+00:00 shinyapps[9471128]: No server contexts or server.R available for /srv/connect/apps/s...

It was there before also, and seems to happen right before the parsing error.

  1. rstudio/rmarkdown# 2500: this seems to work also; we get errors sometimes such as the one below, but the app normally works after we refresh, with no need for a restart.

2023-07-20T16:56:47.993120+00:00 shinyapps[9471103]: Error in extract(input_str) : Invalid nesting of html_preserve directives
2023-07-20T16:56:47.993142+00:00 shinyapps[9471103]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2023-07-20T16:56:47.993160+00:00 shinyapps[9471103]: Execution halted
2023-07-20T16:56:47.993168+00:00 shinyapps[9471103]: Shiny R Markdown document exiting ...

As agreed I will open a support ticket at this point, thanks a lot!

@yassinza
Copy link

Hi @gadenbuie , I Just wanted to update you on this. We are using both fixes together now.

This is the error we see:

2023-07-25T15:39:15.940766+00:00 shinyapps[9471103]: Output created: r-tutorial.html
2023-07-25T15:39:15.946706+00:00 shinyapps[9471103]: Error: lexical error: invalid char in json text.
2023-07-25T15:39:15.946738+00:00 shinyapps[9471103]: NA
2023-07-25T15:39:15.946745+00:00 shinyapps[9471103]: (right here) ------^
2023-07-25T15:39:15.946751+00:00 shinyapps[9471103]: Execution halted
2023-07-25T15:39:15.946755+00:00 shinyapps[9471103]: Shiny R Markdown document exiting ...

The app works fine upon refreshing the page though. Thanks!

@mbaynton
Copy link

So I think there must be two root causes here that are different depending on whether the tutorial is running under RStudio or under connect. We'll still need to research @yassinza's connect/shinyapps.io variant, but the RStudio one is probably this:

You can reproduce this most of the time by running on a remote instance of RStudio so that there is some network latency involved, and double-clicking on the Start Tutorial button. Each click launches an rmarkdown render.
If you're running locally, the button is removed too quickly for the second click to be registered.

@gadenbuie gets most of the credit for identifying that the error message is caused by a corrupted html file and that one way to generate such a file is to render it twice concurrently. All I really did from there was think like a user 😁

@mbaynton
Copy link

mbaynton commented Aug 1, 2023

We've continued to pursue this and there are now bugs open in Connect, RStudio Server, and rmarkdown. Thank you for your patience!

@yassinza
Copy link

yassinza commented Aug 2, 2023

Thanks a lot! Let me know if I can help in any way.

@profandyfield
Copy link
Author

Sorry for my silence - just got back from leave. We switched to teaching with posit cloud this year instead of a campus-install of RStudio run over a network via a software hub and we've had hardly any (maybe none?) of these errors. I think this corroborates the network latency/double click explanation of the error because when we used the software hub RStudio we had endless issues with the network connection between the users PC and Rstudio being slow that we just don't get with posit cloud. Anyway, thought this info might be worth sharing.

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

No branches or pull requests

6 participants