rstudio / rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
http://rstudio.github.io/rsconnect/
134 stars 82 forks source link

New URI Malformed error in most shinyapps.io Apps #537

Closed szmsu2011 closed 3 years ago

szmsu2011 commented 3 years ago

Starting from hours ago today, I noticed most Shiny Apps on shinyapps.io broke on Chromium-based browsers (e.g., Chrome and Edge) with the following error:

image

The same error messages occur in almost all other shinyapps.io Apps I visited. However, Safari is unaffected.

I am not sure if I should have posted this on RStudio forum, but this issue needs to be urgently pronounced.

aronatkins commented 3 years ago

I do not see URIError problems when using Google Chrome 92.0.4515.159 (Official Build) (x86_64) and I'm not aware . The application https://nz-stefan.shinyapps.io/commute-explorer-2/ appears to be working; could you please check again from your end?

szmsu2011 commented 3 years ago

It could be a problem of my own computer, but I have no clue on where to start troubleshooting (I merely tried rebooting).

Do you have any idea, based on the error messages, what might be wrong?

I am using the same Chrome version as yours, which is Version 92.0.4515.159 (Official Build) (64-bit).

szmsu2011 commented 3 years ago

Could you also confirm that if you are using Windows 10 and is up-to-date?

szmsu2011 commented 3 years ago

The issue resolved itself hours ago.

Thanks anyways for the reply.

aronatkins commented 3 years ago

Thanks for letting us know, @szmsu2011. I'm closing this issue, as we've had no other similar reports.

lmetz commented 3 years ago

I also saw this behavior on all apps our organization has hosted on shinyapps.io. It started around the same time @szmsu2011 reported this issue and just disappeared this morning. We also noted that we were getting the same error on Firefox. Additionally, the behavior was only observed when accessing the website from machines on our orgs network. Apps were functioning normally when accessed from personal computers at home.

I know this issue is closed and I'm not sure that it should be reopened since it has disappeared for us as well. I just thought it might be helpful to add our experience here in case there is an actual issue to resolve.

szmsu2011 commented 3 years ago

Hi there,

I wish to reopen this issue as this the problem returned, and by inspecting the sources using Chrome's DevTools, the issue seem to be in <username>.shinyapps.io/<appname>/__assets__/lib/transport/receiver/eventsource.js:

'use strict';

var inherits = require('inherits')
  , EventEmitter = require('events').EventEmitter
  , EventSourceDriver = require('eventsource')
  ;

var debug = function() {};
if ("production" !== 'production') {
  debug = require('debug')('sockjs-client:receiver:eventsource');
}

function EventSourceReceiver(url) {
  debug(url);
  EventEmitter.call(this);

  var self = this;
  var es = this.es = new EventSourceDriver(url);
  es.onmessage = function(e) {
    debug('message', e.data);
    self.emit('message', decodeURI(e.data));
  };
  es.onerror = function(e) {
    debug('error', es.readyState, e);
    // ES on reconnection has readyState = 0 or 1.
    // on network error it's CLOSED = 2
    var reason = (es.readyState !== 2 ? 'network' : 'permanent');
    self._cleanup();
    self._close(reason);
  };
}

inherits(EventSourceReceiver, EventEmitter);

EventSourceReceiver.prototype.abort = function() {
  debug('abort');
  this._cleanup();
  this._close('user');
};

EventSourceReceiver.prototype._cleanup = function() {
  debug('cleanup');
  var es = this.es;
  if (es) {
    es.onmessage = es.onerror = null;
    es.close();
    this.es = null;
  }
};

EventSourceReceiver.prototype._close = function(reason) {
  debug('close', reason);
  var self = this;
  // Safari and chrome < 15 crash if we close window before
  // waiting for ES cleanup. See:
  // https://code.google.com/p/chromium/issues/detail?id=89155
  setTimeout(function() {
    self.emit('close', null, reason);
    self.removeAllListeners();
  }, 200);
};

module.exports = EventSourceReceiver;

The error seemed to be on line 21:

image

Could you please confirm if this issue is related to shinyapps.io or possibly another third party?

Thank you in advance.

lmetz commented 3 years ago

@aronatkins, I can verify that this issue has returned for us as well. I also verified that the error is being thrown from the same line @szmsu2011 noted above. It seems that the timing we are seeing of the issue coming and going is also very similar to @szmsu2011. Please let me know if there is anything I can offer to help troubleshoot the problem.

aronatkins commented 3 years ago

Thanks for letting us know. We have now seen this problem and are actively investigating.

We believe that the problem is somehow tied to an update we made to SockJS, which is used behind the scenes to help Shiny applications work with a variety of networks (the default Shiny websocket can sometimes be challenging with certain intermediate proxies).

This same SockJS update was also at fault when this issue was originally filed, but we did not originally connect this problem to that update because of other issues on our end.

The SockJS problem is not visible to all users; it depends on your browser and the network between shinyapps.io and you. There are a number of ways that SockJS can communicate with the shinyapps.io servers hosting your Shiny application, and only some of those ways cause this problem.

We were not seeing this problem in our testing because only some of the communication techniques (protocols) experience this issue. The one with the problem is not the one most commonly used.

An additional complication to us seeing this problem earlier: The late-August update was reverted, which explains why this happened only for a few days.

aronatkins commented 3 years ago

@lmetz and @szmsu2011 - Any chance you can share other URLs / applications that are experiencing this problem? I see the error from the https://nz-stefan.shinyapps.io/commute-explorer-2/ application, but was hoping to find additional examples. The commute explorer application has a hefty set of package dependencies, which is proving complicated to deploy into some of our testing environments.

lmetz commented 3 years ago

Unfortunately we don't have any public facing apps that I can share. I did look around in the Shiny User Showcase and was able to reproduce the issue on New Zealand Trade Intelligence app. I checked the repo and it didn't appear to have a particularly light set of package dependencies so I'm not sure if that will be any better. I tried to find an example app in the more simple set of Shiny Demos, but wasn't able to find one that throws the error for me yet.

aronatkins commented 3 years ago

Thanks for looking, @lmetz. I'm still digging, but the problem appears related to some of the messages sent between the server (Shiny) and the client (JS). There are unescaped percent (%) characters communicated as hsl(233, 9%, 25%) causing the decodeURI error (that example is one of the backgroundColor values). I'll update as we learn more.

aronatkins commented 3 years ago

With the help of the Shiny team, we have a small example application that demonstrates the same errors reported here.

We have reverted the change that occasionally caused problems with % characters in data communicated from Shiny to the browser. Running instances of your application may need to be restarted, but on restart, they should no longer see errors.

Linking things together -- this was also reported on our community site: https://community.rstudio.com/t/new-uri-malformed-error-in-most-shinyapps-io-apps/115985

Thanks for reporting the reoccurrence of this issue.

lmetz commented 3 years ago

Thanks @aronatkins and team! You all are awesome. I was able to verify that the issue is no longer appearing on our apps.

aronatkins commented 3 years ago

Thanks for the update, @lmetz. I'm glad we finally understand the problem!

I'm going to close this issue for now, but please let us know if you encounter similar issues down the road.