| 383 | } |
| 384 | |
| 385 | void authenticate(Duration minTimeout, Duration maxTimeout) |
| 386 | { |
| 387 | if (!running.load()) { |
| 388 | VLOG(1) << "Ignoring authenticate because the driver is not running!"; |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | authenticated = false; |
| 393 | |
| 394 | if (master.isNone()) { |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | if (authenticating.isSome()) { |
| 399 | // Authentication is in progress. Try to cancel it. |
| 400 | // Note that it is possible that 'authenticating' is ready |
| 401 | // and the dispatch to '_authenticate' is enqueued when we |
| 402 | // are here, making the 'discard' here a no-op. This is ok |
| 403 | // because we set 'reauthenticate' here which enforces a retry |
| 404 | // in '_authenticate'. |
| 405 | copy(authenticating.get()).discard(); |
| 406 | reauthenticate = true; |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | LOG(INFO) << "Authenticating with master " << master->pid(); |
| 411 | |
| 412 | CHECK_SOME(credential); |
| 413 | |
| 414 | CHECK(authenticatee == nullptr); |
| 415 | |
| 416 | if (flags.authenticatee == scheduler::DEFAULT_AUTHENTICATEE) { |
| 417 | LOG(INFO) << "Using default CRAM-MD5 authenticatee"; |
| 418 | authenticatee = new cram_md5::CRAMMD5Authenticatee(); |
| 419 | } else { |
| 420 | Try<Authenticatee*> module = |
| 421 | modules::ModuleManager::create<Authenticatee>(flags.authenticatee); |
| 422 | if (module.isError()) { |
| 423 | EXIT(EXIT_FAILURE) |
| 424 | << "Could not create authenticatee module '" |
| 425 | << flags.authenticatee << "': " << module.error(); |
| 426 | } |
| 427 | LOG(INFO) << "Using '" << flags.authenticatee << "' authenticatee"; |
| 428 | authenticatee = module.get(); |
| 429 | } |
| 430 | |
| 431 | // We pick a random duration between `minTimeout` and `maxTimeout`. |
| 432 | Duration timeout = minTimeout + (maxTimeout - minTimeout) * |
| 433 | ((double)os::random() / RAND_MAX); |
| 434 | |
| 435 | // NOTE: We do not pass 'Owned<Authenticatee>' here because doing |
| 436 | // so could make 'AuthenticateeProcess' responsible for deleting |
| 437 | // 'Authenticatee' causing a deadlock because the destructor of |
| 438 | // 'Authenticatee' waits on 'AuthenticateeProcess'. |
| 439 | // This will happen in the following scenario: |
| 440 | // --> 'AuthenticateeProcess' does a 'Future.set()'. |
| 441 | // --> '_authenticate()' is dispatched to this process. |
| 442 | // --> This process executes '_authenticatee()'. |