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

Connection fails after a minute of inactivity #126

Closed
christakopoulosa opened this issue Oct 15, 2018 · 1 comment
Closed

Connection fails after a minute of inactivity #126

christakopoulosa opened this issue Oct 15, 2018 · 1 comment

Comments

@christakopoulosa
Copy link

@christakopoulosa christakopoulosa commented Oct 15, 2018

Log output
2018-10-15T10:52:36.905038+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=GET path="/websocket/" host=myapp.herokuapp.com request_id=62ff6c68-a766-46a2-9a44-f3f4f6aebab0 fwd="165.225.81.40" dyno=web.1 connect=1ms service=77186ms status=503 bytes= protocol=https

I want to use my heroku app as a dashboard so I would have extended periods of inactivity. How is that possible without my application shutting down due to an idle connection?

@virtualstaticvoid
Copy link
Owner

@virtualstaticvoid virtualstaticvoid commented Nov 13, 2018

Hi @christakopoulosa

This is a known issue on Heroku, since websocket connections are disconnected after a period of inactivity. See the Heroku documentation on HTTP Routing - Timeouts and Long-polling and streaming responses for more information.

The simplest way to solve it, is to have a "keep alive" mechanism, as the following example shows, taken from shiny issues #2110.

Here's a simple solution to increment a counter every 10 seconds.

JS

var socket_timeout_interval;
var n = 0;

$(document).on('shiny:connected', function(event) {
  socket_timeout_interval = setInterval(function() {
    Shiny.onInputChange('alive_count', n++)
  }, 10000);
});

$(document).on('shiny:disconnected', function(event) {
  clearInterval(socket_timeout_interval)
});

CSS

#keep_alive {
  visibility: hidden;
}

server.R

output$keep_alive <- renderText({
  req(input$alive_count)
  input$alive_count
})

ui.R

textOutput("keep_alive")

Furthermore, the Shiny documentation has a article on Reconnecting to Shiny apps which may help, although I haven't tried this.

See also issue #97.

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

2 participants