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

Guarantee FIFO ordering if timestamps are identical. #69

Merged
merged 4 commits into from
Sep 14, 2018

Conversation

jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Sep 14, 2018

On virtualbox (where system timer seems to have less resolution, perhaps?) we
were seeing native later calls being executed in a different order than they
were scheduled, due to the timestamps being identical and the Callback class
not knowing how to break ties. Now we're keeping count with an integer.

Testing notes

You can run this code in R to check whether the bug exists. I highly recommend restarting the R session after running the test, especially if you intend to run it again, or else you may encounter false positives.

  Rcpp::sourceCpp(code = '
    #include <Rcpp.h>
    #include <later_api.h>
    
    void* max_seen = 0;
    
    void callback(void* data) {
      if (data < max_seen) {
        Rf_error("Bad ordering detected");
      }
      max_seen = data;
    }
    
    // [[Rcpp::depends(later)]]
    // [[Rcpp::export]]
    void checkLaterOrdering() {
      max_seen = 0;
      for (size_t i = 0; i < 10000; i++) {
        later::later(callback, (void*)i, 0);
      }
    }
    ')
  checkLaterOrdering(); while (!later::loop_empty()) later::run_now() 

You can also load a Shiny app via Shiny Server (OS or Pro), and use gdb -p 'pgrep R' (those single-quotes are intended to be backticks) to attach to the R process. Then hit Refresh repeatedly and quickly in the browser, this should cause a segfault. (On stock SSP setups you'll eventually hit a "Too many concurrent connections", this is an intended feature of SSP and not indicative of a bug.)

On virtualbox (where system timer seems to have less resolution, perhaps?) we
were seeing native later calls being executed in a different order than they
were scheduled, due to the timestamps being identical and the Callback class
not knowing how to break ties. Now we're keeping count with an integer.
@jcheng5 jcheng5 force-pushed the joe/bugfix/fifo-ordering branch from 0fa1105 to 5a32279 Compare September 14, 2018 02:04
@jcheng5
Copy link
Member Author

jcheng5 commented Sep 14, 2018

Fixes rstudio/httpuv#171

#include "callback_registry.h"
#include "debug.h"

boost::atomic<unsigned long> nextCallbackNum(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long long

@jcheng5 jcheng5 merged commit b4656ca into master Sep 14, 2018
@jcheng5 jcheng5 deleted the joe/bugfix/fifo-ordering branch September 14, 2018 22:57
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

Successfully merging this pull request may close these issues.

2 participants